Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug MaterialOverride broken on every second entity

Discussion in 'Graphics for ECS' started by Fiffe, Feb 11, 2023.

  1. Fiffe

    Fiffe

    Joined:
    Dec 10, 2014
    Posts:
    19
    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.

    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.

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

    Code (CSharp):
    1. [BurstCompile]
    2.         private partial struct PwgAnimationJob : IJobEntity
    3.         {
    4.             public EntityCommandBuffer CommandBuffer;
    5.             public float DeltaTime;
    6.      
    7.             [BurstCompile]
    8.             private void Execute(in Entity entity, in PwgAnimatorData animatorData, in PositionOverrideData positionOverrideData)
    9.             {
    10.                 PwgAnimatorData animator = animatorData;
    11.                 PositionOverrideData positionOverride;
    12.                 SizeOverrideData sizeOverride;
    13.          
    14.                 animator.Time++;
    15.                 ref PwgAnimatorBlob animatorBlob = ref animatorData.AnimatorBlob.Value;
    16.                 ref PwgAnimationClipBlob clip = ref animatorBlob.Clips[animator.ClipIndex];
    17.  
    18.                 if (animator.Time < 16)
    19.                 {
    20.                     CommandBuffer.SetComponent(entity, animator);
    21.                  
    22.                     return;
    23.                 }
    24.  
    25.                 animator.Time = 0;
    26.                 int frameIndex = animator.FrameIndex;
    27.                 ++frameIndex;
    28.              
    29.                 if (frameIndex >= clip.SpriteBlobs.Length)
    30.                 {
    31.                     frameIndex = 0;
    32.                 }
    33.  
    34.                 PwgSpriteBlob blob = clip.SpriteBlobs[frameIndex];
    35.                 animator.FrameIndex = frameIndex;
    36.                 sizeOverride.Value = new float4(blob.Size.x, blob.Size.y, 0, 0);
    37.                 positionOverride.Value = new float4(blob.Position.x, blob.Position.y, 0, 0);
    38.  
    39.                 CommandBuffer.SetComponent(entity, animator);
    40.                 /*CommandBuffer.SetComponent(sortKey, entity, sizeOverride);*/
    41.                 CommandBuffer.SetComponent(entity, positionOverride);
    42.             }
    43.         }
    The shader is very simple, both Size and Position properties are set to Override Property Declaration: Hybrid Per Instance.

    upload_2023-2-11_19-2-1.png

    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.
     
    Last edited: Feb 11, 2023
  2. Fiffe

    Fiffe

    Joined:
    Dec 10, 2014
    Posts:
    19
    It looks like the problem fixed itself after deleting and recreating the shader graph.
     
    JussiKnuuttila and Arnold_2013 like this.
  3. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    540
    Interesting. I have probably the same problem. will try to recreate shader.
    upload_2023-5-8_14-0-10.png