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

Question Unity ECS PostTransformMatrix no show in baking preview when object uniform scale

Discussion in 'Entity Component System' started by UDN_41c53a1a-0daa-4677-a552-0a2e49c9be23, Aug 29, 2023.

  1. UDN_41c53a1a-0daa-4677-a552-0a2e49c9be23

    UDN_41c53a1a-0daa-4677-a552-0a2e49c9be23

    Joined:
    Dec 28, 2016
    Posts:
    28
    hello

    when I want to change the scale no-uniform, from the example
    https://github.com/Unity-Technologi...ets/HelloCube/2. IJobEntity/RotationSystem.cs

    just like this
    Code (CSharp):
    1.  
    2. void Execute(
    3.              ref LocalTransform transform
    4.             ,ref PostTransformMatrix postTransform
    5.             ,in HelloCubeRotation rotationSpeed
    6.             )
    In Entity baking preview, if the object before baking, the scale is 1,1,1, the PostTransformMatrix IComponentData will not show in the preview, and in script can't execute because can't find PostTransformMatrix too.

    uniform.jpg

    Only change the object scale to no-uniform, like 1,2,1, the PostTransformMatrix will show in the baking preview, and script can execute.
    no-uniform.jpg

    So if i have a object scale is 1,1,1, but have to change to 1,2,1, how to do this?
    I have try to AddComponent when baking

    Code (CSharp):
    1.  
    2. AddComponent(entity, new PostTransformMatrix
    3.             {
    4.                 Value = math.float4x4(1,0,0,0,
    5.                 0,2,0,0,
    6.                 0,0,1,0,
    7.                 0,0,0,1)
    8.             });
    but the PostTransformMatrix still no show in preview, it seems to be removed auto, when it detect the object is uniform-scale. so how to change a uniform scale object to no-uniform-scale?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,975
    TransformUsageFlags has a flag for forcing that component to exist.
     
  3. UDN_41c53a1a-0daa-4677-a552-0a2e49c9be23

    UDN_41c53a1a-0daa-4677-a552-0a2e49c9be23

    Joined:
    Dec 28, 2016
    Posts:
    28
    Code (CSharp):
    1.  
    2. var entity = GetEntity(TransformUsageFlags.Dynamic);
    3. AddTransformUsageFlags(entity, TransformUsageFlags.NonUniformScale);
    4.  
    It works. Thanks.