Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Feature Request 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:
    297
    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:
    213
    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:
    272
    has there been a resolution on this?
     
  4. daniel-holz

    daniel-holz

    Unity Technologies

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