Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Bug BuiltinMaterialPropertyUnity_MatrixPreviousM cannot be accessed

Discussion in 'Graphics for ECS' started by argibaltzi, Jan 7, 2023.

  1. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    221
    Hello

    I have a problem with 2 meshes (1 has physics, other has not) and i enable and disable each one them as i need them.

    The problem is when i switch, i need to copy all matrix and state from one to another but i get a VISUAL GLITCH for 1 frame and i think its caused from motion vectors or some shader stuff.

    The only thing i am not able to copy now is the BuiltinMaterialPropertyUnity_MatrixPreviousM data....
    that struct is internal and i can't access it

    What am i supposed to do for such a case? Can that problem be fixed in another way?
    Thanks!
     
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    352
    One way to fix this problem is to access the LocalToWorld component of these kinds of Entities using a read/write handle. This marks the LocalToWorld as "updated", which will then cause the Entities Graphics package to automatically update the previous matrix.
     
  3. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    221
    Can you elaborate how exactly i would do that?
    I am using straight get/set component at the moment

    Code (CSharp):
    1. frameCmd.SetComponent<LocalToWorld>(pairs[i].Ragdoll, EntityManager.GetComponentData<LocalToWorld>(pairs[i].NonRagdoll));
    2. frameCmd.SetComponent<WorldTransform>(pairs[i].Ragdoll, EntityManager.GetComponentData<WorldTransform>(pairs[i].NonRagdoll));
    3.  
     
  4. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    352
    Setting the LocalToWorld transform like that should be OK. When is the 'frameCmd' executed? It should be executed before EntitiesGraphicsSystem for things to work properly.
     
  5. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    221
    Its done immediately, after this piece of code runs.
    I am not sure what else could be wrong really

    I copy the matrix from object 2 to 1,
    enable object 1,
    disable object 2

    There is still 1 frame glitch
    the disabled object 2 is in another location previously because its not getting updated.

    So copying matrix information from object 1 should put it where it should be. I wonder if the physics system causes the glitch
     
  6. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    221
    I have a lot of other problems with frame 1, when i load objects the first frame they are blurred. It seems to be blending 2 matrix states (one where its now, and another somewhere else, maybe identity)

    How are these problems fixed???
     
  7. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,349
    You would need to add EntityQueryOptions.IncludeDisabledEntities to your EntityQuery in MatrixPreviousSystem for that to work correctly. Otherwise you have one frame where the entity was just enabled and the current LocalToWorld is updated but the previous matrix is still whatever it was when the entity was disabled, and won't be updated until right after the matrix was uploaded to the GPU.
     
    JussiKnuuttila likes this.
  8. azmi_unity

    azmi_unity

    Joined:
    Dec 13, 2020
    Posts:
    62
    I'm having the same problem. It looks like BuiltinMaterialPropertyUnity_MatrixPreviousM is only updated after it gets uploaded to GPU.

    My workaround is to set ForceNoMotion for the instantiated object for that first frame, and resetting it back afterwards.