I'm currently trying to create up to four different nodes of the same instantiated scene. Basically a "player join screen", where a specific input can join and quit at each consecutive call.
My instance root is PathFollow2D with a sprite.
The current Scene has a Path2D to receive those instances as child nodes.
My InputActions are mapped to 4 different keys, each one calling the same generic node spawn function with a different parameter value. The Node spawns with a color that goes to define the sprite modulation, node name:
func input(event: InputEvent) -> void:
if Input.isactionjustpressed("REDclick"):
setplayerin("RED")
if Input.isactionjustpressed("GREENclick"):
setplayerin("GREEN")
if Input.isactionjustpressed("BLUEclick"):
setplayerin("BLUE")
if Input.isactionjustpressed("YELLOWclick"):
setplayer_in("YELLOW")
func set_player_in(color) -> void:
if players_in.has(color) == false:
var neuron := preload("res://Game Elements/Player/Neuron.tscn").instance()
players_in.append(color)
player_count += 1
neuron.set_name(color + "neuron")
neuron.set_modulate(COLORS[color])
circuit.add_child(neuron)
print(players_in)
else:
players_in.erase(color)
player_count -= 1
circuit.get_node(color + "neuron").queue_free()
print(players_in)
So far it works, but I'm finding it hard to fine tune initial parameters for the instantiated scene such as its child nodes specific properties.
Before this, I thought It was better just to add the child instance and call a method inside its own script to set all its parameters at the moment of initiation of the node. That was not working, so I resorted to the code I now paste here.
What would be the best logic to implement this?