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.

Bug AddComponent() in Baker cannot add PostTransformScale().

Discussion in 'Entity Component System' started by wechat_os_Qy09AtTzCAF9FWIJIvuFRFhfs, Mar 16, 2023.

  1. wechat_os_Qy09AtTzCAF9FWIJIvuFRFhfs

    wechat_os_Qy09AtTzCAF9FWIJIvuFRFhfs

    Joined:
    Jun 17, 2021
    Posts:
    5
    I tried to Add PostTransformScale in a baker. it won't show up in the inspector window and the Entities.ForEach would not run if it's declare "ref PostTransformScale postTransformScale".

    So It seems like not a inspector window problem, the PostTransformScale not been added at all.
    Part of my baker file is like:
    AddComponent(new TestComponentData()
    {
    testValue = 1;
    });
    AddComponent(new PostTransformScale(){
    Value = float3x3.Scale(authoring.defaultScale)
    });

    The System Update is like:
    Entities.ForEach((ref TestComponentData data, ref LocalTransform localTransform, ref PostTransformScale postTransformScale) => {});

    Then the TestComponentData() did show up in the inspector window and the PostTransformScale did not. The system won't run
     
  2. wechat_os_Qy09AtTzCAF9FWIJIvuFRFhfs

    wechat_os_Qy09AtTzCAF9FWIJIvuFRFhfs

    Joined:
    Jun 17, 2021
    Posts:
    5
    My Unity Version is : 2022.2.10
    entities: 1.0.0-pre.47
     
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,609
    It's not a bug. Because TransformBaking responsible for that process will remove your PostTransformScale if your authoring game object scale is uniform.
    Code (CSharp):
    1.  
    2. if (chunkHasPostTransformScale && requestedHasPostTransformScale)
    3. {
    4.     postTransformScales[i] = new PostTransformScale { Value = postTransformScale };
    5. }
    6. else if (requestedHasPostTransformScale)
    7. {
    8.     var componentTypes = new ComponentTypeSet(ComponentType.ReadWrite<PostTransformScale>(),
    9.         ComponentType.ReadWrite<PropagateLocalToWorld>());
    10.     Commands.AddComponent(unfilteredChunkIndex, entity, componentTypes);
    11.     Commands.SetComponent(unfilteredChunkIndex, entity, new PostTransformScale { Value = postTransformScale });
    12. }
    13. else if (chunkHasPostTransformScale)
    14. {
    15.     Commands.RemoveComponent<PostTransformScale>(unfilteredChunkIndex, entity);
    16. }
    17.