Search Unity

LocalToWorld matrix on an entity FAILS to update in a specific scenario

Discussion in 'Entity Component System' started by TRS6123, Oct 22, 2018.

  1. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    If a GameObject has all the following components:
    -GameObjectEntity
    -CopyTransformFromGameObjectComponent
    -CopyTransformToGameObjectComponent
    -PositionComponent
    -RotationComponent
    -ScaleComponent
    the associated entity's LocalToWorld matrix fails to update.

    The issue disappears when you either:
    1) Remove both CopyTransforms components, or
    2) Remove any of the other components (Position, Rotation, or Scale)

    This issue began in 0.0.12 preview.18 and persisted into 0.0.12 preview.19
     
    Last edited: Oct 23, 2018
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    CopyTransformFromGameObjectComponent
    CopyTransformToGameObjectComponent

    I don't think you should have both of these on same entity, it doesn't really make sense. It should be one or the other.

    If you have both aren't you just either copy transform from GameObject to entity then back to GameObject or the other way around. When would that be the intended behaviour?
     
  3. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    The issue I illustrated above also occurs when only one of the CopyTransform components is attached to a GameObject.

    This is how I understand using both a CopyTransformFromGameObjectComponent and a CopyTransformToGameObjectComponent on the same entity:
    -Attaching a CopyTransformFromGameObjectComponent allows you to edit the Position and Rotation of an entity with the move and rotation tools as well as the Transform Editor in the Inspector
    -Attaching a CopyTransformToGameObjectComponent allows you to "publish" changes made to the Position and Rotation Components in any user-defined ComponentSystem
    -Behaviour will depend on the update order of all active ComponentSystems
    -Any ComponentSystem that writes to the Position or Rotation of an entity should simply be updated after CopyTransformFromGameObjectSystem and before CopyTransformToGameObjectSystem (just use the UpdateAfter and UpdateBefore attributes)
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    -edit- read bottom, there is definitely some type of issue here with the 2 copy systems though.

    I still don't really understand your use case for this

    CopyTransformFromGameObjectComponent - Is used to drive your entity transform from legacy components on a GameObject (eg. RigidBody) but want to integrate with ECS.

    CopyTransformToGameObjectComponent - is used when using legacy components on a GameObject (eg. MeshRenderer) but want to drive the transform from ECS.

    Using them both at the same time doesn't make sense and really just doesn't work, because one of them will be overridden by the other system.

    If CopyTransformToGameObjectSystem runs first, then you can't change values on the transform in the inspector because they are overridden before CopyTransformFromGameObjectSystem is run.

    If CopyTransformFromGameObjectSystem runs first, then you can't change values of Position/Rotation components because they are overridden before CopyTransformToGameObjectSystem is run.

    I just tested, and this works fine for me.

    upload_2018-10-23_9-9-58.png

    After some random transform manipulations

    upload_2018-10-23_9-12-27.png

    -edit-

    Actually you might be onto something here. It works fine for me but the CopyTransformFromGameObjectSystem stops working randomly if I click on the entity in the debugger which is kind of strange. The CopyTransformToGameObjectSystem also suffers a similar problem. Inspecting the hybrid entity seems to break the 2 systems.
     
    Last edited: Oct 22, 2018
  5. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    Does removing the Position, Rotation, Scale, or CopyTransformFromGameObjectComponent from your example above make everything else work again as expected? Because if it does, you may have duplicated the issue I'm having.

    The Position/Rotation components won't be overridden if actions are performed in this order:
    1) Use move tool, rotation tool, and/or Inspector to modify hybrid entity's Transform (occurs outside of the Update group)
    2) Run CopyTransformFromGameObjectSystem so that Position/Rotation Components match the Transform
    3) Run all user-defined JobComponentSystems that read from and/or write to Position/Rotation Components
    4) Run CopyTransformToGameObjectSystem so that modifications to Position/Rotation Components are reflected in the Transform