Do instanced meshes have their own parent?

I’ve been googling around and can’t find a clear answer to this, and when I try it, it does not seem to work.

Basically I am making a game.
I load several meshes which form parts of enemies.
Then for each enemy I add several parts.
Each enemy has its own transform node for movement and animation - I parent each instance to that enemies transform node.
Everything seems to load right and the enemies animate, but the instanced meshes just sit their in the middle of the screen - they don’t seem to be parented to the enemies they are a part of.

Is it possible to do it this way or do I need to clone meshes?

I feel like I read somewhere that all instanced meshes must have the same parent. It may be possible to force the instances to move by adjusting the world matrix buffer (Instances | Babylon.js Documentation). Honestly, in my experience, unless you have a lot of instances, clones are not much less performant. I would build your enemy hierarchy and then use instantiateHierarchy on the root mesh. Also a PG that shows what you are trying to do will go a long way to getting better and faster help in these forums. Sometimes it can also benefit you by shedding light on what you are missing.

Thanks for the info - but I figured it out. The mesh was dynamically created, and I just needed to call ‘makeGeometryUnique()’ on it before instancing it - and everything worked!

Don’t know why, but it works.

2 Likes

Regular instanced meshes are their own objects so they can have their own parent information to calculate the world matrix with, it wouldn’t be possible only if you were using Thin instances since these don’t create objects :slight_smile: