I have 2 entities, A and B, and I want B to move together with A if A is moved from the editor or via scripting.
To do that, I wanted something similar to entity.on(“attr”, function(name, value, prev) {}); that works with the entity’s properties, such as position, rotation and scale.
I’m sorry if this is a duplicate. I looked around the documentation and forum and couldn’t find anything like that. Is there an event listener for that?
One could say I can make B a child entity of A, but this doesn’t apply to my use case because I also want A to render after B (If I place B as a child of A in the hierarchy, B is visually displayed above A and I want the opposite).
I don’t believe there are any events for when the transform of the entity changes. Typically, this is implemented using a parent-child as you said. Are you talking about UI? As that is where parent-child order defines rendering order, but not for typical 3d geometry.
Yes, they were entities inside a 2D screen for the UI.
I managed to achieve what I wanted by nesting the A and B in the correct order inside a group entity, which I then attached as a child of the main entity.
With that I could manage the order of rendering and also move them all together with the parent main entity without hard struggles.
You may want to implement your own ‘update’ for the UI so that the Entities can be updated in a specific order or fire your own events for when your code updates transforms for Entities.