Unique RenderAttributes per obj

Started by Josplode · one year ago · 7 replies · 266 views

#1
Josplode
Member
JoinedApr 2023 Posts4 Score105
I am trying to set a unique render attribute on each object in my scene, and I want something like this:

GetComponent<ModelRenderer>().Attributes.Set( "MyColor", myColor);
.. but that isn't doing anything. I also tried making a clone of the OverrideMaterial per object.

I know the material is set up correctly internally at least as this works, but it affects every object:

Scene.RenderAttributes.Set( "MyColor", myColor);

Does anyone have an example that works?
#2
garry
Facepunch
JoinedApr 2021 Posts436 Score2,270
I would expect what you're doing there to work
#3
Braxen 🐟
Member
JoinedJun 2021 Posts189 Score190
you'll also need to do
SceneObject.Batchable = false;
otherwise it will "bleed" over to other objects using that model
#4
Josplode
Member
JoinedApr 2023 Posts4 Score105
Hmm ok cool that probably means I lose some optimizations like instancing maybe?
#5
Josplode
Member
JoinedApr 2023 Posts4 Score105
Looks like I needed:

GetComponent<ModelRenderer>().SceneObject.Attributes.Set( "MyColor", myColor);
(On the SceneObject instead of the ModelRenderer itself)
edited one year ago#6
garry
Facepunch
JoinedApr 2021 Posts436 Score2,270
That makes some sense, but did GetComponent<ModelRenderer>().Attributes even work? I don't really see how it could have - that member doesn't exist? We should create it?
#7
Braxen 🐟
Member
JoinedJun 2021 Posts189 Score190
Renderer.Attributes does not exist, no
edited one year ago#8
Josplode
Member
JoinedApr 2023 Posts4 Score105
Ah sorry this is what I tried that didn't work, botched it when I was simplifying the example

GetComponent<ModelRenderer>().GetMaterial().Attributes
edited:
I could see maybe needing to create unique material instances per object or something, but I couldn't see the result of this at all even globally
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.