Search Unity

Resolved Bake uniform scale into LocalTransform's scale field instead of PostTransformMatrix

Discussion in 'Physics for ECS' started by Kmsxkuse, May 14, 2023.

  1. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    306
    PostTransformMatrix is a massive float4x4 component that swallows up 64 bytes per entity that has the component.

    In the physics documentation, it states: When a GameObject with non-identity scale is baked, the non-identity scale data is baked to a PostTransformMatrix component (to preserve the scale of the render mesh at bake time).

    Furthermore, using the scale field on the LocalTransform is already supported at runtime.

    I would like to suggest that when the scaling factor on a GameObject at bake is uniform but non-identity such as scale = (2, 2, 2), physics baking should instead bake the uniform scale into the LocalTransform.Scale field instead of constructing a PostTransformMatrix as it does currently.

    Either automatically detect this using a difference threshold across all three dimensions such as how TransformBaking does so or a toggle-able option (there's already a lock button on GO transform scale but that's just for inspector and doesn't enforce uniform scaling).

    Why is this important? Because having massive 4x4 matrices that is otherwise redundant to a single field in an existing component is beyond wasteful. Chunk capacity is already in the low 20s with all the other components required for gameplay, adding on 64 bytes means possibly single digit chunk capacity.

    Extremely low chunk capacity has significant impact on DOTS performance and reaching single digits means practically no difference from a game-object implementation of the same mechanics.

    Sure, I could in editor set all my gameobjects to have a uniform scaling factor but when I want my rigidbodies to be slightly uniformally smaller or bigger than another otherwise identical rigidbody I have two options: create an entirely different entity with hardcoded application of the scale to the parameters (not just physics authoring but the render mesh and other properties as well) or make a custom baking system that strips the PostTransformMatrix from entities that have uniform scales.

    What I mean is a rather hacky workaround to have a baking system run late in the baking world, such as during PostBakingSystemGroup, that checks for uniform scaling factors in created post transform matrices and removes them. The uniform scaling is then applied to the LocalTransform component.

    As mentioned on discord, pinging @daniel-holz
     
    daniel-holz likes this.
  2. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    278
    Thanks for the suggestion.
    It feels like this is the right thing to do.
    There might be some pitfalls I am not immediately seeing here though.
    I'll file a ticket internally and discuss this with the team.
     
    Kmsxkuse likes this.
  3. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    has there been a resolution on this?
     
  4. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    278
    We've been actively working on this. Keep your eyes peeled for upcoming releases.
     
    Bas-Smit and Kmsxkuse like this.
  5. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    306
    Just saw this in the [1.1.0-pre.3] - 2023-10-17 since it was highlighted in the November DOTS development report. Only now I got around to reading up on the changelog.

    Thanks for that. Keep up the good work.
     
    daniel-holz likes this.
  6. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    278
    Thanks! Will do. And you all keep the good feedback and suggestions coming! :)

    There is more stuff in the new release btw that was requested, such as easier ways to modify collision filters.
    Have a look through the latest documentation. The 1.2-exp1 version of the docs are the most recent and also apply to the latest 1.1 release. We couldn't quite get the documentation updates ready in time for the latest 1.1 release drop. They might get updated still in the coming weeks. In the meantime, resort to the 1.2 docs if you feel something is missing.

    Here two insightful and recently updated pages:
    https://docs.unity3d.com/Packages/com.unity.physics@1.2/manual/concepts-data.html

    https://docs.unity3d.com/Packages/com.unity.physics@1.2/manual/physics-collider-components.html
     
    Kmsxkuse and Anthiese like this.