How to modify or input user data for each instance in ECS using the BRG method

I understand that Unity ECS uses the BRG (BatchRendererGroup) approach for rendering objects. After reading the BRG documentation, I have a question.

In the BRG documentation, the following part caught my attention:

</
m_BatchID = m_BRG.AddBatch(metadata, m_InstanceData.bufferHandle);
>

It seems that metadata (which I believe refers to the metadata declared with UNITY_DOTS_INSTANCED_PROP in DOTS instancing shaders) can be used to distinguish between each instance’s InstanceData (custom data for each instance). With this, it looks possible to assign different UV values, colors, or scales to each instance.

I’m curious how we can inject custom data like this into the ECS rendering system, such as with RenderMesh. Among the methods I’ve found, the most promising one seems to be Material Property Override. Is this the best approach? Or is there another method that I should consider?

Let me know if you need any further adjustments!

Yup. Material Property Overrides (either using one of the built-in components or defining your own with the [MaterialProperty] attribute is how to go about it with Entities Graphics.

1 Like

Does material property override only work in the shader graph, or can it also be implemented in HLSL code? If possible, could you provide some guidance on this?

Custom shaders can be written to support DOTS instancing (Entities Graphics page, Unity 6 Manual page) which leads to per-instance modification on its own. All that’s needed is appropriate (instanced) declaration for each property. You can see a sample shader here.

1 Like