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.

Read Renderer.material only if it's instantiated

Discussion in 'General Graphics' started by Alex_StudioDrydock, Dec 6, 2019.

  1. Alex_StudioDrydock

    Alex_StudioDrydock

    Joined:
    Jan 16, 2019
    Posts:
    9
    Hi, I'd like to be able to read a Renderer's currently-assigned material without instantiating a specific instance if it's not already instantiated. i.e., something like:

    Code (CSharp):
    1. if (renderer.hasMaterialInstantiated)
    2.     return renderer.material;
    3. else
    4.     return renderer.sharedMaterial;
    This is so that I can render to a CommandBuffer from within a
    PostProcessEffectRenderer without specific knowledge of whether each renderer has had a specific material instantiated.

    Is this possible?

    Thanks
    Alex.