Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Material (Instance) vs Material

Discussion in 'Scripting' started by BP_, Oct 4, 2015.

  1. BP_

    BP_

    Joined:
    Dec 11, 2013
    Posts:
    8
    To give a quick summary, when I hit "Left Control" I want my GameObject's Material to change to a new Material.

    I have the materials loaded for use:
    Material x = Resources.Load("Path") as Material;

    When I check the current material:
    Material current = gameObject.GetComponent<Renderer>().material;

    I get MaterialName (instance) so when I try to see if x == currentMaterial to change the color, it is not registering them as the same.

    Any help would be appreciated!
     
  2. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    access it via sharedMaterial

    Material current = gameObject.GetComponent<Renderer>().sharedMaterial;
     
    Last edited: Oct 4, 2015
    BP_ likes this.
  3. BP_

    BP_

    Joined:
    Dec 11, 2013
    Posts:
    8
    Thanks, I'll try this when I get home!

    Edit: It worked perfectly, thanks.
     
    Last edited: Oct 5, 2015