Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

How to get the second element in render?

Discussion in 'Scripting' started by xOSSxKratos, Nov 12, 2021.

  1. xOSSxKratos

    xOSSxKratos

    Joined:
    Apr 4, 2021
    Posts:
    11
    Long story short. I need to change the element 1 render material element on trigger event. I have most of the code down but hit a wall, and I can't find any info about this.

    Screenshot (2).png Screenshot (3).png

    The above code works for changing the element0 material element in the render, but I need element1 to change.
    I think its a change I have to make to line 14, but I'm not sure what it's missing.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
  3. xOSSxKratos

    xOSSxKratos

    Joined:
    Apr 4, 2021
    Posts:
    11
    There has to be a way to access the second element in the renderer. Without having to change all that.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    Cool. When you find it, be sure to let Unity know so they can update their documentation.

    https://docs.unity3d.com/ScriptReference/Renderer-materials.html

    You can read all day long from any entry in the .materials property.

    Changing a single entry has precisely the same restrictions that any other native side array property has.

    Good luck!
     
  5. xOSSxKratos

    xOSSxKratos

    Joined:
    Apr 4, 2021
    Posts:
    11
    I just ended up doing what I had to do in a animation. At least in a animation I can control the different elements. It just ends up being a different trigger. Thanks for your help.
     
    Kurt-Dekker likes this.