Godot Version
Godot 4.2.1 Stable
Question
Hey there! I’m currently working on a character customization system in Godot 3D. I wanted to start off by making the skin tone changeable, so we’re trying by making a system that flips through an array of 3 materials via the
surface material override on our meshes.
I setup my customization scene with a background and imported in the scene of my model.
I tried making variables to refer to the meshes of my Base model (which has
been imported in as a Kinematic Body 3D with a collision shape, in case that changes anything here.)
I couldn’t use normal variables, so the engine told me to use @onready var for them all.
However, when I went to test my scene I get an error for every single piece of the mesh, 11 pieces, 11 errors, saying Node not found at the end of each error.
I made it so the scene of my model lets you edit the children and copied the node paths for each piece of the model (the pieces that would be affected by the skin tone change, like the head and other limbs.)
Here is my script :
extends Control
const baseAngel = preload(“res://Meshes/Angels/Base_Angel.glb”)
#Skin
var skinTones: Array = [“res://Meshes/Angels/SkinTones/Misc/Base.tres”,“res://Meshes/Angels/SkinTones/Tan/Tan1.tres”,“res://Meshes/Angels/SkinTones/Dark/Dark1.tres”]
var skinToneIndex: int = 0
#Body
@onready var Head = $Root/Base_Angel/Armature/Skeleton3D/Head
@onready var Ears = $Root/Base_Angel/Armature/Skeleton3D/Ears/Ears
@onready var LeftArm = $Root/Base_Angel/Armature/Skeleton3D/LeftArm
@onready var LeftFoot = $Root/Base_Angel/Armature/Skeleton3D/LeftFoot
@onready var LeftHand = $Root/Base_Angel/Armature/Skeleton3D/LeftHand
@onready var LeftLeg = $Root/Base_Angel/Armature/Skeleton3D/LeftLeg
@onready var RightArm = $Root/Base_Angel/Armature/Skeleton3D/RightArm
@onready var RightFoot = $Root/Base_Angel/Armature/Skeleton3D/RightFoot
@onready var RightHand = $Root/Base_Angel/Armature/Skeleton3D/RightHand
@onready var RightLeg = $Root/Base_Angel/Armature/Skeleton3D/RightLeg
@onready var Wings = $Root/Base_Angel/Armature/Skeleton3D/Wings
Called when the node enters the scene tree for the first time.
func _ready():
update_skin_tone()
func update_skin_tone():
var currentSkinTone = skinTones[skinToneIndex]
#Changing skin tones via Surface Material Overrride
Head.material_override = currentSkinTone
Ears.material_override = currentSkinTone
LeftArm.material_override = currentSkinTone
LeftFoot.material_override = currentSkinTone
LeftHand.material_override = currentSkinTone
LeftLeg.material_override = currentSkinTone
RightArm.material_override = currentSkinTone
RightFoot.material_override = currentSkinTone
RightHand.material_override = currentSkinTone
RightLeg.material_override = currentSkinTone
#Function called when player presses the “Skin” Button
func _on_skin_tone_pressed():
skinToneIndex = (skinToneIndex +1) % skinTones.size()
update_skin_tone()
My model, “Base_Angel” is a glb imported and saved as a scene as a Kinematic Body3D and the script is attached to a button node that is made to change the skin tones.
I noticed that all my variables are listed as null as well, as if it’s not being recognized at all…
I’ve tried a few different approaches like having the angel be local to the customization screen, but I really am stumped! For now I gave the Base_Angel scene an “editable children” setting, so I could see the pieces I needed to reference.
I just don’t get how to reference my imported mesh in GDscript for my variables.
Thank you so much for reading, this is my first 3D project as well, so this is new territory!