Topic was automatically imported from the old Question2Answer platform.
Hello, I am trying to make a checkpoint system, that if the player has entered an area. The player’s spawn point would change to that area’s location.
That I want to restart the scene or reload it in some way. so that everything resets when the player dies or clicks the restart button. BUT, it should retain the player’s spawn point to that area’s location.
I have tried using a singleton named “Global”. It has a vector3 and a function that updates the vector3 when the function is called.
followed this guy’s tutorial for that, but in his example, he was using 2d:
Here is where I call the func update spawn in the area node
Also followed this guy’s tutorial:
I tried to make it so that the area node’s vector3 would be saved and could be loaded back when the player restarts.
here is the Save script (basically copied the Tiny Legions’s code):
When the player dies it shows a ui where there would be a button named “Restart”.
And this is the code on what happens when the button is clicked.
The problem is when I run it and restarts it, it says the code below:
I am unsure on what to do and I am open for other alternative methods on making a checkpoint system that meets my goal.
Did You by any chance add your Global to group “Saved” ?
Because what error says is You have just queued free your global script :). I assume it happened during loading.
Yep, I added it to a group “Saved”. I am unsure tho of what to do. What can I do to fix it?
parataposna | 2022-08-03 01:17
Look what happens :
When You load a game You attempt to delete current existing nodes and replace it with new ones. Their older ID is deleted, and new nodes get new ID.
But Your autoloaded script, referred to as Global, is supposed to have original ID, because the rest of the script depends on it.
So You can’t queue it free. Remove it from “Saved” groups, and save/load its contents manually. What kind of data do You want Global to save and load ?
Inces | 2022-08-03 13:07
Oh, I get it now. Thanks for the explanation. For the data, I want the coordinates of a checkpoint that a player has been set to. So might it be possible to save only the translation of the checkpoint and make it not depend on the old node’s ID?
parataposna | 2022-08-04 14:40
In your save system You draw chosen data from your nodes using get_save_stats function. This function translates nodes properties to Strings. Strings are lined one below the other for every saved node in one file. Every node has the same things saved - parent and position. Your Global script doesn’t have parent nor position, so it would throw different error later anyway.
You want the Global to save only last checkpoint position.
So You need to store it manually. In save_game() function, before it closes file, add line :