How to duplicate a MeshInstance in a scene and make the Material unique at the same time.

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

When you duplicate a MeshInstance, the Material and Mesh will refer to the same ones from the original MeshInstance.
I know that if I want to play with the Material separately, I can make it unique.
But, you can make them unique, but it’s hard to make dozens of objects unique one by one.

Is there any way to make them unique at the same time as duplicating them?
Or, is there a way to make all objects unique at once?

You duplicate in editor (like ctrl+D) or in code ?

BigBadWouf | 2022-02-04 20:38

Have you tried overriding the material on the mesh? There’s a way to do it, but the method currently escapes me.

Ertain | 2022-02-04 20:47

In editor. ctrl+D.

huny | 2022-02-04 20:55

I also tried Material override. The result was the same.

huny | 2022-02-04 20:56

:bust_in_silhouette: Reply From: Inces

You can go to Resource property of original mesh and material and set local_to_the_scene as true. But if I recall correctly, there is a problem with duplicate itself, and it might still not work.

Still the result is the same, I don’t even know what the Local to scene property is for.

huny | 2022-02-06 06:54

It works if scene is instanced from code, it makes every new instance automatically to “make_unique”. As I suspected, this does not work with duplicating, both in code and in editor. I am afraid You have to duplicate naked mesh scene without material and set it after. Or You can create a scene from meshinstance with material and make “new_inherited_scene” from it. It should work better than duplicate.

Inces | 2022-02-06 10:57

Excuse me, but what does it mean to create a scene from meshInstance? What does “newinherited_scene” mean?
I’m not very good at English, so I don’t know what you’re talking about…

huny | 2022-02-06 13:04

:bust_in_silhouette: Reply From: 9a5405


Another thing you can try is instantiating the mesh and material in code to make it unique rather than reply on reusing nodes.

Something like this:

I am struggling with how to make it duplicate on the editor instead of during the game run. It is not possible to duplicate in code.

huny | 2023-03-17 12:33