Search Unity

Renderer.sharedMaterial/sharedMaterials always seems to return Instances?

Discussion in 'Scripting' started by peerssa, Aug 21, 2018.

  1. peerssa

    peerssa

    Joined:
    Aug 13, 2015
    Posts:
    5
    I thought this was supposed to return the base asset, not an instance? Is this something new? Using 2018.1.6f1.

    EDIT: This is the code am using to access:

    MeshRenderer[] meshRenders = GetComponentsInChildren<MeshRenderer>();
     
    Last edited: Aug 21, 2018
  2. bovesan

    bovesan

    Joined:
    Nov 30, 2017
    Posts:
    5
    I just discovered that if you first access material(s), you will loose the link to the shared. I guess this is because Unity creates duplicates when you access material(s), and even sharedmaterial(s) will point to those.