instantiate a glb model,bug the material is auto load,how to make it unique,so i can change the material not affects other instance mateiral.
and can make the material unique by import?
if i drag the glb to scene, there’s no way to make it unique.
if by code like this:
item_scene = scene.instantiate()
add_child(item_scene)
var scene_mesh=item_scene.mesh
# 获取第一个 surface 的材质
var mat =scene_mesh.surface_get_material(0)
if mat:
mat = mat.duplicate()
mat.set_shader_parameter(“mahjong_texture”, res_item.texture)
scene_mesh.surface_set_material(0,mat)
it still affacts other instance. i’m confused,anyone can help me?what’s the best way to make it not shared?
ps:i also tried the local to scene in the material,and get the same problem
===============more demo==========
github:GitHub - jinruozai/unique_material_test: bug test
in the demo,i’ve check both the material and shade file resource_local_to_scene.
and in the root script, i use the duplicate(true). i tried all i can try,but not find the right way:
extends Node3D
@onready var plane1:MeshInstance3D = $Plane1/Plane @onready var plane2:MeshInstance3D = $Plane2/Plane
func set_plane_mat(tag,tex):
var mat:ShaderMaterial = tag.mesh.surface_get_material(0)
if mat:
var newmat=mat.duplicate(true)
newmat.set_shader_parameter(“material_icon”, ICON_1)
tag.mesh.surface_set_material(0,newmat)
it’s a glb file. in the glb inspector, click make unique of the material will get a noti “changes may be lost”
if inherited the glb,"make unique "button is gray and can’t click.
i’ve try a lot. not only the mesh unique,but the material and the shader are all unique,but not work. i am really confuseed wthe the share logic of the material.
and why after mat.duplicate() and mat.duplicate(true) also affects each other
How can you use it on top of using an original material? I am of the belief that it replaces the material in that slot? I don’t believe it works like a decal. So if you were using it for another effect then wouldn’t the original change no longer matter anyway, because you won’t be able to see the material being overridden? If you have other slots they won’t be affected so you could have one change on one slot and use another slot for “another effect”? Or if your other effect is temporary then you could try storing it’s value in a variable and then reapplying it when you want the “original” value back?
In regard to duplicating the material, are you sure you’re not confusing changes to the meshes material being propagated across rather than changes to the material being propagated across? E.g. are you sure your not using the same mesh and continually applying different materials to it, rather than different materials all getting affected by the same change?
Thank you so much for your detailed explanation! I now realize that I misunderstood material_override as something like material_overlay. With your clarification, the issue is perfectly resolved. I see now that I shouldn’t have focused so much on modifying the original material—this was entirely my mistake. Thanks again for your help!