Reload a Node after its state has been changed during the game. how to do that?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By yeeshu06
:warning: Old Version Published before Godot 3 was released.

Good day,

I have some items, which when the player collides with its state changes in to a different texture. Now at some point of the stage, EVIL STRIKES!!! and those items have to be regenerated (in original state, which means he has to go back and collect).

How can i just ‘reload’, ‘regenerate’ that specific node. I tried killing it first using ‘queue free’ but keeps giving null instance cos i think its being used elsewhere. ANy help would be great.

Thanks

:bust_in_silhouette: Reply From: Zylann

You are getting “null instance” error because queue_free destroys the node. If you destroy it you won’t be able to respawn it unless you reload the level.

I see two ways of reloading:

  1. Add a state to your node for when it has been “picked”, “killed” or whatever. Also, put it in a group, for example “respawners”. So when that happens, just hide it and disable its collisions if any. Then when you respawn, call a method on all nodes in the “respawners” group to reset them to their initial state (that you store in _ready), and show them back.

  2. The other way around, you can also reload the entire level by deleting and re-instancing it, or using SceneTree.reload_current_scene ( ). This will reset everything to where it was, however you would need to “remember” any special states in a parent node or in a singleton, if needed.

Thanks for the answer. Appreciate it. So there is no command for ‘reloading’ a certain node. Unless its a whole scene?

yeeshu06 | 2017-07-26 09:28