How to pass the code discard instancing?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kyla

3d project
I have two players, using the same material,
One was hit, I made him red,
But because of the same material, when I turn the material red, both players turn red.
I just want to make a player red.
How to do

:bust_in_silhouette: Reply From: SIsilicon

You can replace the material with a duplicate.

#I'm assuming that material override is the one you want the instancing to be discarded
material_override = material_override.duplicate()

That .duplicate() is found in all objects inheriting from Resource. It makes a copy of the resource which pretty much discards instancing.

:bust_in_silhouette: Reply From: eons

Discard instancing is to put all the nodes of an instanced scene in the current edited scene (in editor).


What you see happens because all Resource types are shared by default (same reference) to save system resources.

And to change that you can make the Material resource “local to scene”, check your material resource, the option to make it local should be at the bottom on the inspector.
This will duplicate the resource when the scene is instanced (be careful to not use that when not needed).