I need to set _ObjectId for some shader to work. I tried using material overrides but it doesn’t work.
[MaterialProperty("_ObjectId")]
public struct MaterialPropertyObjectId : IComponentData
{
public int Value;
public MaterialPropertyObjectId(int value)
{
Value = value;
}
}
The _ObjectId is always zero:



Basically, I want the DOTS equivalent of MaterialPropertyBlock.SetInteger().
It doesn’t appear that that particular shader variable is made to be DOTS-instancing compatible. Your options are to either modify the shader or make a new material and modify that.
How do I modify the shader to make it compatible? I tried using Properties but it doesn’t work. I’ve read that material overrides only works with Shader Graph but I’m not sure about that.
They works just fine with properly manually written shader.
1 Like
Does you have somehting like this in your shader?
float _ObjectId;
#ifdef UNITY_DOTS_INSTANCING_ENABLED
UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)
UNITY_DOTS_INSTANCED_PROP(float, _ObjectId)
UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)
#define _ObjectId UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float, _ObjectId)
#endif
And you have instance id set, either manually or through Unity macro, for vertex input struct (if you access instanced property in vertex function) and/or for fragment input struct (if you access instanced property in fragment function) like
UNITY_VERTEX_INPUT_INSTANCE_ID
And have set it in the beginning (before any instanced property usage) of your vertex/fragment function?
UNITY_SETUP_INSTANCE_ID(IN);
(And if you access in fragment shader you properly transfer it from vertex shader)
UNITY_TRANSFER_INSTANCE_ID(IN, OUT);
1 Like