#Proper way to set transform on instantiated prefabs in DOTS?
1 messages · Page 1 of 1 (latest)
you only need LocalTransform. everything else will be updated by Transform group
this is a problem actually if you're using end simulation command buffer etc to instantiate
it'll appear in the world at 0,0,0 for a frame before transform system runs
if you're using ECB you should usually set the LocalToWorld as well
One other obstacle you may run into when instantiating a prefab through an EntityCommandBuffer: as a side effect of the recent Transform system changes is that the transform values are all packed into a single component instead of separate Translation/Rotation/Scale components. In order to set the transform for a newly-instantiated instance (which doesn't exist yet, at ECB recording time), you must provide an entire LocalTransform object; there's no way to say "set the position to XYZ, but keep the prefab's rotation and scale".
We're working on a way to fix this in a future release, but in the meantime one workaround is to use a ComponentLookup<LocalTransform> to read the prefab entity's LocalTransform, modify as needed, and pass the modified value to EntityCommandBuffer.SetComponent<LocalTransform>(myNewEntity, modifiedPrefabTransform)
This is an easy fix, by adding additional ecb command