MaterialOverride broken on every second entity

Hello,
I’ve been working on an animation system based on sprites and textures in ECS but this error simply prevents me from continuing.

I am using Unity 2022.2.0b16 and entities.graphics 1.0.0-pre.15.

8798542--1196263--Unity_uKondFHq2m.gif

As you can see in the gif - the MaterialOverride is only working on every second entity. I am not doing anything complicated here - simply changing the UV position of a material on per instance basis every 16 frames in an IJobForEach. The entity prefab is a simple quad with a material assigned to it and an authoring component to create the animation data.

8798542--1196266--upload_2023-2-11_18-55-58.png

[BurstCompile]
        private partial struct PwgAnimationJob : IJobEntity
        {
            public EntityCommandBuffer CommandBuffer;
            public float DeltaTime;
      
            [BurstCompile]
            private void Execute(in Entity entity, in PwgAnimatorData animatorData, in PositionOverrideData positionOverrideData)
            {
                PwgAnimatorData animator = animatorData;
                PositionOverrideData positionOverride;
                SizeOverrideData sizeOverride;
          
                animator.Time++;
                ref PwgAnimatorBlob animatorBlob = ref animatorData.AnimatorBlob.Value;
                ref PwgAnimationClipBlob clip = ref animatorBlob.Clips[animator.ClipIndex];

                if (animator.Time < 16)
                {
                    CommandBuffer.SetComponent(entity, animator);
                  
                    return;
                }

                animator.Time = 0;
                int frameIndex = animator.FrameIndex;
                ++frameIndex;
              
                if (frameIndex >= clip.SpriteBlobs.Length)
                {
                    frameIndex = 0;
                }

                PwgSpriteBlob blob = clip.SpriteBlobs[frameIndex];
                animator.FrameIndex = frameIndex;
                sizeOverride.Value = new float4(blob.Size.x, blob.Size.y, 0, 0);
                positionOverride.Value = new float4(blob.Position.x, blob.Position.y, 0, 0);

                CommandBuffer.SetComponent(entity, animator);
                /*CommandBuffer.SetComponent(sortKey, entity, sizeOverride);*/
                CommandBuffer.SetComponent(entity, positionOverride);
            }
        }

The shader is very simple, both Size and Position properties are set to Override Property Declaration: Hybrid Per Instance.

I am not really sure what I am doing wrong here but it seems that even if I remove the system and job and completely delete all my code to simply switch to a MaterialOverride component made by Unity it simply won’t work on every second entity too.

I would really appreciate any help with this, hopefully I am not the only one struggling with this feature.

It looks like the problem fixed itself after deleting and recreating the shader graph.

2 Likes

Interesting. I have probably the same problem. will try to recreate shader.