The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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.


in Engine by (75 points)

1 Answer

0 votes

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.

by (29,360 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.