#MaterialProperty Override For Hybrid Per Instance Property on Custom URP Shader

1 messages · Page 1 of 1 (latest)

dry atlas
#

Recently had the task of refactoring a system to ECS and currently trying to convert a regular feature that changes a shader's property per instance. I'm aware of the whole setup with MaterialProperty, but for some reason, while the component values do change, the properties do not, so I set a simpler example with cubes and a basic shader with only a _Color property such that:

[MaterialProperty("_Color")]
public struct MaterialOverrideTest : IComponentData {
    public float4 Value;
}```

Where the _Color property reference has been set to Hybrid Per Instance and the shader itself set to allow material overrides.
 and a simple system:
```csharp
public partial class CubeColorSystem : SystemBase {
    protected override void OnUpdate() =>
        Entities.WithAll<MaterialOverrideTest>()
                .ForEach((ref MaterialOverrideTest materialOverrideTest) => {
                     var time = (float)SystemAPI.Time.ElapsedTime;
                     materialOverrideTest.Value = new float4(math.sin(time), math.cos(time), 0, 1);
                 }).ScheduleParallel();
}```

And the ``MaterialOverrideTest `` component values do change as expected, yet the materials are unchanged.

I'm wondering if I'm missing anything here. Tested on 2022.3 and 2023.2.
faint crest
#

Show your shader code where you access per instance property. Or property in graph inspector if you’re using shader graph.

dry atlas
#

Shader itself is ShaderGraph set this way

faint crest
#

just to be clear MaterialOverrideTest component lies on the same entity where render components lies? Do you see your cube with default color you’ve set on material?

dry atlas
#

The test Entities in question are gameobjects within a SubScene, such that the MaterialOverrideTest component is added through an Authoring script to the same objects.

faint crest
#

Ok, good, is your subscene closed?

#

I mean checkbox on right side of subscene in hierarchy

dry atlas
#

It was not
And now that I did, it seems to be working
And now I feel dumb

ashen fox
#

If you change your scene view to show runtime instead of authoring it should work with open subscene

#

(in preferences entities)