Does it make sense to organize entities by parenting?
Entity a= commandBuffer.CreateEntity(aArchetype);
Entity b= commandBuffer.CreateEntity(bArchetype);
commandBuffer.AddComponent(b, Parent)
//b.Parent = a
So the last line (out commented line) does not work. How would it work? And is this something anybody does? Just to keep the entity overview organized for example?
Cheers
Vlad
You can use Parent to organize entities, but it is important to understand that the transform components (Translation, Rotation, and Scale) are all relative to the parent transform. So if you move the parent, the child will follow. If you want to set the child to a specific world position, you’ll need to account for the parent’s transform each frame.
Unfortunately, there isn’t really any better alternative to organizing entities in the editor. But this is a known issue and something they plan to work on eventually. More info here: [Experimental Entities 0.51 is Available]( Experimental Entities 0.51 is Available page-2#post-8335152)
Btw, the code to set up a parent/child relationship using a command buffer looks something like this:
Entity a = commandBuffer.CreateEntity(aArchetype);
Entity b = commandBuffer.CreateEntity(bArchetype);
commandBuffer.AddComponent(b, new Parent { Value = a });
// This line is needed if you want the transform systems to actually move the child relative to the parent.
commandBuffer.AddComponent<LocalToParent>(b);
1 Like