Godot Version
Godot_v4.4.1-stable_win64
Question
Can I save and Instanced Child to Load later using a Config File?
I’m making an avatar creator and I want to be able to save and load all the things a player chooses for their character to load into another scene eventually. I was following a tutorial on using Config Files to save player data and it works perfectly for the name value but I am stuck on getting it to save the hairstyles and their color that instance in on top of a node 3D that holds the position of where the hair should sit on the player model. (Pics below for better context!)
Remote Debug Example of Hair Mesh being instanced (No children when no instance which is default) :
Saving data works but loading the data I get this error :
Trying to assign value of type 'Array' to a variable of type 'Node3D'.
on this line :
hair_instance = config.get_value("PalSettings", "HairInst")
Save/Load Section of Script :
#Hair :
@export var hair_instance : Node3D
@export var hair_color : ColorPicker
#Facial Features :
func _on_save_pressed():
var config = ConfigFile.new()
config.set_value("PalSettings", "PalName", pal_name.text)
config.set_value("PalSettings", "HairInst", hair_instance.get_children())
#config.set_value("PalSettings", "HairColor", hair_color.color)
config.save("user://PalSettings.cfg")
print("Pal Saved!")
func _on_load_pressed():
var config = ConfigFile.new()
var result = config.load("user://PalSettings.cfg")
if result == OK:
pal_name.text = config.get_value("PalSettings", "PalName")
hair_instance = config.get_value("PalSettings", "HairInst")
#hair_color.color = config.get_value("PalSettings", "HairColor")
printerr("Error while loading save file! May be corrupted or missing!")#Save Data Variables
#Name :
@export var pal_name : LineEdit
Example of Hair Instance script (There is a button for every hair style with this function on pressed) :
func rogerhair_inst():
var RogerHairScene = preload("res://Meshes/Angels/Hair/HairInstScenes/RogerHair.tscn")
var RHinst = RogerHairScene.instantiate()
var RogerHPos = $"../../../../Base_Angel/Armature/Skeleton3D/NeckBone/HairPos1"
#Remove Existing Children
for child in RogerHPos.get_children():
child.queue_free()
#Add Child
RogerHPos.add_child(RHinst)
#Checking for Instance
if is_instance_valid(RHinst):
pass
#----------------------------------------------------------------------------------------------------------------------------
func _on_roger_hair_btn_pressed():
#Runs the Roger Hair Instance func
rogerhair_inst()
#Playing Animation
AP.play("Posing001")
I’m also wondering if I have to set the config within each instance button instead of the save/load section? Thank you for reading!