Search Unity

Question Static PhysicsCollider - Remove Rotation/Translation components

Discussion in 'Physics for ECS' started by charleshendry, Nov 1, 2020.

  1. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    97
    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.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Have you tried adding the StaticOptimizeEntity script? Or is it still being added?
     
    Last edited: Nov 1, 2020
  3. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    97
    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.
     
  4. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    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.
     
  5. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    97
    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?
     
  6. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    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.
     
    charleshendry likes this.