Node not being updated properly after Instantiation

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

I’m currently trying to make a small popup whenever your selection box is over an item with a custom animation, however I’m running into an issue where it seems to ignore the update() function that it’s supposed to run every time after it becomes instantiated whenever the selection box moves over to another slot with an item, which results in a box being instantiated at the top of the parent node without any changes.

Below are images of the issue in action, along with the code for the sections responsible for instantiating the node and the code associated with the node itself. Any help I could get fixing this would be greatly appreciated!

Instantiate Code
Name Popup Box Code


Hi, cute game. My guess is that when you call namePopup = get_node("MenuRight/ItemNamePopup")
You’re getting the old popup, or an error, the new popup will probably be named something weird at this point since you need to use add_child(new_child, true) in order to not get weird names with @ in them.
But also, when you call queue_free() on the old popup it doesn’t leave right away. (it’s queued to be removed at the end of the frame).
You can remove it from it’s parent immediately, which might avoid the name issue, with something like:

func clear() -> void:
  queue_free()
  get_parent.remove_child(this)

But I’d recommend just not using the name to keep track of it at all, with just a small change you can do the same thing without needing to get the node by it’s name.

	if inv.itemInv[selectedOption] != null:
		print("Adding Name Popup and setting variables!")

		#First save the new instance
		namePopup = nameNodePath.instantiate()

		#Then pass it to add_child()
		$MenuRight.add_child(namePopup)

		#You can also use it to get one of the child nodes 
		# (this name is fine, it will be predictable because it's not added during runtime)
		namePopupText = namePopup.get_node("ItemNameText")

		#The rest is the same
		print("Updating Name Popup with correct name!")
		#....
1 Like

If you want to see what is currently in the scene tree of your running game, you can go back to the editor while the game is running and click the tab beside the “Scene” tab to view the node tree for the game as it’s running, you’ll probably see some of those names with @s in them. Overview of debugging tools — Godot Engine (4.2) documentation in English

thank you, this is just the solution i was looking for! this works far better than the system i was coding. thanks again for responding! i’ve been looking into the debug tools a bit more before this but i didn’t know you could view a scene tree like that, it looks like a super useful feature i’ll have to keep in mind. thanks again for the help!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.