Hi ! I have a parent entity with several children. Some of these children need to have a non-uniform scale so I added a component PostTransformMatrix after adding the Parent component to them. The problem is that if I add this PostTransformMatrix component, the children's position is no longer updating as I move the parent (however the scale and rotation are).
I can send you more info if needed (git repository, screen captures...). I would be very grateful if someone knew how to solve this issue.
#Children stop moving with parents when I add PostTransformMatrix
1 messages · Page 1 of 1 (latest)
what's the value of that matrix?
is it valid?
potentially you may be overwriting position with invalid matrix, but I'm not sure enough if that's possible
The values are valid since the entities are displayed (values are between 0 and 0.4). They are just placed in world space rather than local space.
Until I find a solution I calculate the world position of children based on the parent position and update it every frame... Not ideal but it works
Actually simply adding an empty PostTransformMatrix (so all floats set to 0 by default) has this effect
The position is back to world space
default is invalid
if you want unchanged scale use identity
oh ok. I'll check my values (it cannot hurt to double check)
Thanks for your help!
Here is an example of a matrix's value:
float4x4(0.0285f, 0f, 0f, 0.07916667f, 0f, 0.1306667f, 0f, -0.07466666f, 0f, 0f, 0.01f, 0f, 0f, 0f, 0f, 0f)
The last row of zeroes looks suspicious; shouldn't the last element be 1.0f?
Thank you for your answer. 🙂
The last four 0f are the position of the object and I want it to be (0,0,0,0). It should be local but it is world position (however for another child that is not controlled by the same script, it's also four 0f but the position is local).
On the doc there is written "When adding or modifying this component, add and update the corresponding LocalTransform component." (source: https://docs.unity3d.com/Packages/com.unity.entities@1.0/api/Unity.Transforms.Parent.html)
I wonder if the problem isn't from there. Does someone know how to update it ?
Ok so apparently I just need to do something like
ecb.AddComponent(entity, new LocalTransform{....})
I'm just not sure yet if there is a way to automatically calculate the new coordonates
The comment there refers to the fact that when an Entity's parent changes, its existing LocalTransform value will suddenly be relative to its new parent, instead of the old one. This will likely cause the entity to "snap" to some new, possibly incorrect position. The usually-expected semantics are that the object's world-space position doesn't change when its parent changed, and unfortunately it's currently the user's responsibility to manually update the LocalTransform in this case. We've discussed adding a help function to automate this, similar to the worldPositionStays parameter in UnityEngine.Transform.SetParent()