Changing only One Surface Material of Mesh with Multiple Materials

Godot Version

Godot_v4.3-stable_win64

Question

How can I change the albedo of one Material in my MeshInstance that has two materials?

What can I add to my ColorPicker section to change only one of the materials on my meshinstance3D? I have a dog snout cosmetic and this script changes the snout’s entire material to the albedo color selected but I want the separate nose color to be unchanged by the color picker. Pics and Script Below!

Script :

#FACE COLOR CHANGE HERE.................................................................................................................
@onready var FacePos1 = $"../../../../Base_Angel/Armature/Skeleton3D/NeckBone/FacePos"
var FE_mat3D = StandardMaterial3D.new()

func _on_face_color_picker_color_changed(color):
	print("Face Color Picker changed!")
	#Check if FacePos1 has any children to avoid out-of-bounds errors
	if FacePos1.get_child_count() > 0:
		print("Face instance ready to change!")
		var FacePosChild = FacePos1.get_child(0)
		if FacePosChild is MeshInstance3D:
			print("MeshInstance3D Detected.")
			#Ensure mat3D is a new instance of StandardMaterial3D 
			FE_mat3D.albedo_color = (color)
			FacePosChild.material_override = FE_mat3D
			FE_mat3D.cull_mode = BaseMaterial3D.CULL_DISABLED
			print("Face color changed!")
		else : 
			print("Nothing to change!")
#}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{

Snout When Instanced Into Scene From Customizer :

Snout When ColorPicker is changed :

You would need to use FacePosChild.set_surface_override_material(your_material_index, FE_mat3D) for only one material override.

1 Like

Perfect thank you!

Just for reference current script :

#FACE COLOR CHANGE HERE.................................................................................................................
@onready var FacePos1 = $"../../../../Base_Angel/Armature/Skeleton3D/NeckBone/FacePos"
var FE_mat3D = StandardMaterial3D.new()

func _on_face_color_picker_color_changed(color):
	print("Face Color Picker changed!")
	#Check if FacePos1 has any children to avoid out-of-bounds errors
	if FacePos1.get_child_count() > 0:
		print("Face instance ready to change!")
		var FacePosChild = FacePos1.get_child(0)
		if FacePosChild is MeshInstance3D:
			print("MeshInstance3D Detected.")
			#Ensure mat3D is a new instance of StandardMaterial3D 
			FE_mat3D.albedo_color = (color)
			FacePosChild.set_surface_override_material(0,FE_mat3D)
			FE_mat3D.cull_mode = BaseMaterial3D.CULL_DISABLED
			print("Face color changed!")
		else : 
			print("Nothing to change!")
#}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{
1 Like