+1 vote

Hi I´m having problems with the programming of my game with the death of the player. The thing is that I´m trying to use the gettree().reloadcurrent_scene() in my world node, it just works fine but the problem is that the auto load scripts that I have get their variables cleared, making unplayable my game, because there´s a crash when some action happened in them because the variables are null.
The question is how can I make the "global" scripts to be updated("recapture" the variables again) when I restart the world scene? Consider that this scripts are stored in the "root node" and not in my "world" scene. Thanks in anticipation
Edit: I commented the response of eons giving some important details to this question, if someone knows how to fix it, I would appreciate a lot.

in Engine by (55 points)
edited by

The method reload_current_scene should not affect the autoloaded scripts, how is that variables get cleared on them too?

I checked again and apparently , the only variables that are cleared are the ones that have a node inside them( with getnode()), the others are fine(they are arrays and dictionaries and variables from the inside of the node). Apparently I can fix this by getting the nodes inside the process code, but that would mean I have to rewrite a lot of code. If someone know if you can make the auto load scripts to "reload it´s call to the getnodes and another external variables" I would appreciate it a lot.

1 Answer

+1 vote
Best answer

Connect the autoloaded scripts to the exit tree signal of the scenes where they get the nodes, after receiving the signal, it should wait for the scenes to load, set values and connect again.

Another option is to make the autoloaded scripts store the NodePath instead, if the scene is reloaded, the path may stay the same (depends on the scenes).

by (7,866 points)
selected by

Thanks man, the method of making the variables the path worked perfectly, I had to rewrite a bit the code but with the replace tool of the gdscript editor it wasn`t that bad.

I'm having trouble coding games too. Thanks for good idea to solve the problem.

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 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 webmaster@godotengine.org with your username.