I have some objects I’m converting to Entities using subscene conversion. They have the Physics Shape script attached, which creates a PhysicsCollider component. However this also adds Rotation and Translation components. I don’t want these components on the Entities as they are static and I define rotation/translation at runtime by writing to LocalToWorld as a one off.
Is there any way to prevent Rotation/Translation being added? I’ve tried removing them with a script but they are getting added again by some Unity system. As far as I see, the physics system will work without them as it then uses the LocalToWorld data.
Have you tried adding the StaticOptimizeEntity script? Or is it still being added?
It’s already added. And the physics bodies are picked up by the static bodies part of the physics system, so seems odd it will always add rotation translation as they’re shown as optional in the physics entity query.
If you look in com.unity.physics\Unity.Physics.Hybrid\Conversion\ConversionExtensions.cs, the function PostProcessTransformComponents is adding the Translation and Rotation components.
Note that the extra components are more efficient than decomposing the matrix every frame.
Thanks, but doesn’t that contradict the approach in some of the non-physics systems? E.g. a static entity converted from a subscene will only have a LocalToWorld added, no Translation/Rotation, so no transform system update will happen at runtime.
So adding Translation/Rotation will improve the physics speed, but I think would mean that there would then be a transform system update (TRSToLocalToWorldSystem) each frame?
Personally, my own familiarity is with the Physics system, so I’ll have to ask around.
@SeanParkinson can you speak to this?
If you are happy to tweak the Unity Physics code as a local package you could skip the addition of the unwanted components. If there are not that many independent static bodies the performance difference may not be noticeable anyway.