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!
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.
Can you elaborate how exactly i would do that?
I am using straight get/set component at the moment
frameCmd.SetComponent<LocalToWorld>(pairs[i].Ragdoll, EntityManager.GetComponentData<LocalToWorld>(pairs[i].NonRagdoll));
frameCmd.SetComponent<WorldTransform>(pairs[i].Ragdoll, EntityManager.GetComponentData<WorldTransform>(pairs[i].NonRagdoll));
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.
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
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???
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.
1 Like
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.