Search Unity

Bug Convert To Entity disables Material Override for Sprite

Discussion in 'Graphics for ECS' started by mizak, Jun 13, 2022.

  1. mizak

    mizak

    Joined:
    Jun 5, 2014
    Posts:
    14
    Hey all,

    I am trying to use Material Overrides with a custom SRP compatible shader made in shader graph and then attached to a sprite renderer. The shader works perfectly with a converted to entity GameObject to highlight the sprite. However when I try to use the following code:
    Code (CSharp):
    1. [GenerateAuthoringComponent]
    2. [MaterialProperty("_BaseColor", MaterialPropertyFormat.Float4)]
    3. public struct ColorOverrideComponent : IComponentData
    4. {
    5.     public float4 Value;
    6. }
    7. //In Job
    8. for (int i = 0; i < batchInChunk.Count; i++)
    9. {
    10.     ColorOverrideComponent colorOverride = colorOverrides[i];
    11.     colorOverride.Value = new float4(1f, 0.4078f, 0.6313f, 1f);
    12.     colorOverrides[i] = colorOverride;
    13. }
    14.  
    while referencing DocsLink for the _BaseColor custom property, this does not override the color in either editor mode(manually changing values in inspector) or play mode; The values get set (visible in ECS inspector) but visually nothing happens. I assumed this was because sprite renderer doesn't work with material overrides even though DocsLink2 seems to imply shader graph should work with overrides considering there are no errors and everything else is working fine.

    However the Asset style of material overrides (DocsLink3) works with the custom shader and the sprite in Editor mode; When I uncheck Convert to Entity it also overrides the shader properly in play mode. It seems like the functionality is there but not enabled for the converted entity, perhaps because the Entity that is created by the convert to entity script does not have the RenderMesh and RenderBounds that are expected by the hybrid renderer when processing entities per DocsLink4. It seems like a bug that the hybrid renderer can render the sprites with the custom shader as an entity but cannot override the _BaseColor property at runtime.

    To summarize:
    Working (Override overrides default color in play mode) Scenarios:
    -Sprite Renderer, Custom Shader with Exposed _BaseColor Property, Material from that Shader, Material Override Asset, and Convert to Entity unchecked.
    -Mesh Renderer of default Cube with Material Override Asset, and Convert to Entity checked OR unchecked.

    Not Working (Override does not override default color and it goes back to default color on convert to entity/play mode) Scenarios:
    -Sprite Renderer, Custom Shader with Exposed _BaseColor Property, Material from that Shader, Material Override Asset, and Convert to Entity checked.
    -Sprite Renderer, Custom Shader with Exposed _BaseColor Property, Material from that Shader, Custom Material Override Script with Authoring, System with Job to programmatically change the Override Script float4 values, and Convert to Entity checked. (Though the values do change, there is no visual effect and the color remains default)

    Default mode which works to manually set the _BaseColor:
    -Sprite Renderer, Custom Shader with Exposed _BaseColor Property, Material from that Shader, and Convert to Entity checked with _BaseColor manually set in Inspector.

    Note: I did enable the hybrid per instance checkbox and expose settings in the custom shader property.

    I hope someone has some insight.

    Thanks everyone who takes a look,
    Mike
     
  2. ashzhu

    ashzhu

    Joined:
    Jul 4, 2022
    Posts:
    3
    i met same problem , i try it with mesh renderer,it worked ,but with spriterenderer ,it did't work .
    "The values get set (visible in ECS inspector)" ,i guess it happens beacuse this base Color component just attached to entity ,but did not binding to render's material property
     
  3. salvitre89

    salvitre89

    Joined:
    Sep 13, 2020
    Posts:
    1
    yea i am also running into this now. Spent a long time trying to figure out whats going on, but I was able to get two side by side tests set up. one is using a mesh collider / mesh renderer with a custom shader graph and the other uses the sprite renderer component. Material color override works fine from a script in the mesh setup but does nothing in the sprite renderer game object. really need this to work for my prototype :(
     
  4. Elapotp

    Elapotp

    Joined:
    May 14, 2014
    Posts:
    98