Unique RenderAttributes per obj

Started by Josplode 8 posts 263 views

Reply on sbox.game
  1. #1
    Josplode 105
    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. #2
    garry Facepunch 2,270
    I would expect what you're doing there to work
  3. #3
    Braxen 🐟 190
    you'll also need to do
    SceneObject.Batchable = false;
    otherwise it will "bleed" over to other objects using that model
  4. #4
    Josplode Started this 105
    Hmm ok cool that probably means I lose some optimizations like instancing maybe?
  5. #5
    Josplode Started this 105
    Looks like I needed:

    GetComponent<ModelRenderer>().SceneObject.Attributes.Set( "MyColor", myColor);
    (On the SceneObject instead of the ModelRenderer itself)
  6. edited Feb 2025 #6
    garry Facepunch 2,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. #7
    Braxen 🐟 190
    Renderer.Attributes does not exist, no
  8. edited Mar 2025 #8
    Josplode Started this 105
    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