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

Design time (in Editor) material instancing error

Discussion in 'Editor & General Support' started by Duckocide, Aug 1, 2019.

  1. Duckocide

    Duckocide

    Joined:
    Aug 30, 2014
    Posts:
    35
    Hi

    I've been working on some new procedural generation code where various parameters on a material shader (Shader Graph) are adjusted (weightings, that sort of thing). All working fine at runtime.

    I've extended one of the prefab scripts I use for this to have a companion "editor only" script to monitor for parameter changes and adjust things in the scene (editor). When I change the "material" of a meshrenderer in the prefab, I do of course get the...

    "Instantiating material due to calling renderer.material during edit mode. This will leak materials into the scene. You most likely want to use renderer.sharedMaterial instead."

    ...Error.

    Now I understand this is where I'm not changing the sharedMaterial (and so generating material instances). However, I don't want to do this as I'm simply picking / changing individual prefab script instance related parameters and setting the material relative to them. I don't want to permanently change the underlying material (via sharedMaterial) as these settings are unique to each gameobject in the scene. Not least of which, I need the scene editor to show the variations.

    Whilst I'm not convinced it is doing any harm, it is an annoyance. Is there any way of avoiding this error (perhaps should be a warning rather than an error)?

    Answers / Advice / Observations appreciated :)

    (2019.1)