after moving node to another tree, find_node() can't find that node!
Asked Answered
S

2

0

Simple routine using a key to toggle move an icon between an inventory rack and an (unseen) reserve.
I can move an item from the reserve to the rack, or vice-versa, but only once!
After that, find_node() returns a null.
Is there some kind of refresh I need to do? The Remote panel shows the icon-nodes being moved around (when it works). Since it works both ways, the code has been validated so now I'm clueless what is going on.
This is test code. I move the node back and forth using a key input in my Main script:

	if Input.is_action_just_pressed("6key"):
		AddToInventory("batteries")	
	if Input.is_action_just_pressed("0key"):
		RemoveFromInventory("batteries")
func AddToInventory(b):
	var moveicon = $IconReserve.find_node(b)
	if moveicon != null:
		print("added ",b)
		$IconReserve.remove_child(moveicon)
		$Background/IconRack.add_child(moveicon)
		$Background/IconRack.call('FillRack')
	else:
		print("no ",b," found in reserve")
		for i in $IconReserve.get_children():
			print(i.name)

func RemoveFromInventory(b):
	var moveicon = $Background/IconRack.find_node(b)
	if moveicon != null:
		print("removed ",b)
		$Background/IconRack.remove_child(moveicon)
		$IconReserve.add_child(moveicon)
		$Background/IconRack.call('FillRack')
	else:
		print("no ",b," found in rack")

Snapshot of the scenetree. Full project below. This is V 3.5.3.

inventorydesign.zip
2MB
Sabayon answered 1/3, 2024 at 4:16 Comment(0)
T
0

Sabayon Try find_node(b, true, false) or if you know the exact path from parent consider using get_node() instead.

Toulouse answered 1/3, 2024 at 9:18 Comment(0)
S
0

Toulouse
yay! worked fine. I can't commit to a fixed path at this stage and speed is not a factor in my project.
I really need to remember to go back and read the docs thoroughly on things I use a lot and think I know all about!
thanks

Sabayon answered 1/3, 2024 at 9:41 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.