Godot Version
4.3
Question
I have a weapon wheel UI established with a empty slot and 2 designated slots, and there’s a text that displays “currently equipped” the goal is when the pickaxe is selected in the UI its equipped. basically i just need to understand how to add the pickaxe scene to the player-head. simply hiding it doesnt work for my situation because of various hitboxes and animations.
You can reparent nodes in code through the reparent
function. If you mean to “hide” unequipped tools maybe you can use remove_child
add add_child
to equip?
$PlayerHead.remove_child(last_equipped_tool)
$PlayerHead.add_child(new_tool)
Another option may be hide them and disable processing
last_equipped_tool.visible = false
last_equipped_tool.process_mode = PROCESS_MODE_DISABLED
new_tool.visible = true
new_tool.process_mode = PROCESS_MODE_INHERIT
1 Like
that’s essentially what I’ve been trying. trying both of these returns null.
$Head causes a crash and just head doesn’t do anything but prints in debugger.
Where is your Head located? Could you @export
the head instead? Maybe a scene tree screenshot would do better here.
What does it print in the debugger?
in the debugger it was still just saying null
wheel_ui.gd:25 @ _process(): Parameter “p_child” is null.
if i try @export var head: Node3D = $“…/…/…/Head” it prompts me to use @onready
ah your $pickaxe
is null, not the head. Where is the unequipped tool supposed to be?
Could you search for nodes by name instead of making an if
for each option?
var tool: String = $SelectionWheel.Close()
var new_tool: Node = $Toolbox.get_node(tool)
if equipped_tool:
head.remove_child(equipped_tool)
head.add_child(new_tool)
equipped_tool = new_tool
@export
doesn’t need the path filled in, you would assign it in the inspector.
so i dont have the tools in the world, they each have their own scene with their animations/ code etc. ready to be attached to the player. my hope was i could remove the tool from the world when not in use and instantiate it to the head when called for.
if its not obvious im a noob and have no idea what im doing 90% of the time.
Ah, to totally delete a node use .queue_free()
on it.
var tool: String = $SelectionWheel.Close()
var new_tool: Node = $Toolbox.get_node(tool)
# delete last tool
if equipped_tool:
equipped_tool.queue_free()
# create new tool
new_tool = load("res://Tools/" + tool + ".tscn").instantiate()
head.add_child(new_tool)
equipped_tool = new_tool