Suppress errors from Editor scripts that are inteded effects?

Hi there, playing with more editor scripting. Recently i tossed together another silly tool that overrides every renderer in scene , and replaces with a single shader of chosing, and upon closing the utility it replaces all the original object materials, it all works fine, but in the process, Unity tells me theres an error , and that materials will be leaked into the scene.

Unless theres something im unaware of, this is completely an intended behaviour, and im wondering if there is a way to suppress the error message. Maybe theres something im not aware of, i will gladly take any info on this . Thanks.

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.
1 Like

Its annoying and not surpressable.
What I did is simply doing what the assignement to material does too to work around it.

instead of .material = mat we use .sharedMaterial = Instantiate(mat) (thats what assigning to material does anyway, its always a clone)

Good to know im not the only one. I did find a work around that made it stop squaking at me, but i can only assign a single material override one time before releasing it , replacing originals, than repeating cycle again.

Anyways, thanks for info Dreamora.

EDITED :

I find this to be an interesting excert from the documentation …

and yet the editor is claiming exactly the oppisite via this warning / error. Additionally, it seems i hadnt quite worked around it , cause its still popping up here and there. Im digging a little more into your approach , not sure i quite have it worked out yet.

1 Like

Any solution? I have this problem with Unity 5.1

I got the same error with Unity 5, too. It’s so annoying…

It’s annoying, but right. You have to think about how they are stored.
If you have 20 red cubes and change one .sharedMaterial, all cubes go blue, 1 draw call.
If you have changed .material, the one cube gets his own material and is the only blue one. 2 draw calls.

So there are 2 possibilites: documentation says that you probably just want to change one cube and should use renderer.
But if you do that in edit mode, the material becomes a scene object instead of the material file. If you do that to 200 cubes, you will get 200 materials, so the editor warns you about that.

Think about your intention and ignore the warning if you know it’s right.

2 Likes