I'm currently updating our project from pre8 to pre65 and implementing the changes to how transform data is handled on Entities. I'm trying to understand what the intended workflow is when it comes to determining world position data accurately.
It seems there's three different ways, all of which have serious issues:
- Use LocalTransform values, which are updated in real time during simulation. This seems to be the intended way for setting position as well. Problem is this only works if the Entity has no Parent, so this is not viable when the Entities in our game can frequently be parented/unparented and we still need world position when they are parented.
- LocalToWorld, which only updates after simulation, meaning it is not a viable method for getting positional data during the simulation phase. This is a major issue especially with newly spawned Entities as they'll have default LocalToWorld values unless we manually compute them on spawn. The official manual implies that this is only intended for rendering applications too.
ComputeWorldTransformMatrix()according to the manual this is the intended way to get lag-free, reliable positional data but the documentation on this is sparse to say the least. For one, the manual mistakenly lists this as part ofLocalTransformwhen it is actually part of theHelpersclass. There's also no usage examples I could find, and it's not very clear from the signature what exactly it expects for arguments. (If anyone can share a usage example of this method I'd appreciate that)
From what I can piece together, developers are intended to use this something like this?
- Use LocalTransform to read/write transform data while always making sure the Entities in question are not part of a hierarchy
- Use LocalToWorld for rendering only
- Use ComputeWorldTransformMatrix() to get transform data from anything within a hierarchy.
I have to say I find it baffling the API doc says getting accurate world-space transforms is "relatively uncommon". Almost all use cases for transforms in my experience require world, not local position. Certainly anything involving simulation does. Local space is only useful for positioning something in relation to its parent. So I find it strange that the Unity team decided to make local space the default and world space so cumbersome to access.