Hello.
Can we run “Ready()” only once? So when I start the game for the second time, the code will not work. Please help guys.
What specifically is going wrong with restarting the game? If you can’t run ready twice can you separate some of the ready code into a new function, call that on ready and where you need to restart?
func _ready():
if some_saved_flag_from_the_first_start:
return
#the rest of your code
Or:
func _ready():
if some_saved_flag_from_the_first_start:
the_rest_of_your_code()
Can you be more specific? What exactly doesn’t work?
If I had to explain,
Like Minecraft, you start a world and a random world is created. So, when we start the game, random things spawn in the world thanks to the timer, and I added a save and load system to this game. But I noticed an error: While objects that already exist in the scene are saved with their positions, objects that spawn randomly later disappear when I restart the saved file. So when I start the saved game the game restarts. I thought I could solve the problem if I linked the spam code to ready and ran it once. It’s actually ridiculous, why does the game code start from zero when the objects in the scene start from where they were last? I hope I could explain.
Sounds like you need to save more data or used a seeded RandomNumberGenerator
Thanks, but is there a way to save an object in any scene?
How are you currently saving things? Can you add the object to your current save system?
Are these objects added as children of World?
Yes, with add_child().
Maybe try also setting owner after add_child
add_child(random_thing)
random_thing.owner = self
It works! You saved me again dude. Thanks to you and everyone else.
I know you ended up solving your issue another way, but I do want to post another answer to the question of calling ready more than once, since I did not see it mentioned:
Node request_ready() (RequestReady in C#)
For example, Calling this in _ready
will guarantee that the node is readied each time it is reparented or enters the scene tree
Yes, this is actually the answer to the question in the title.To be honest, when I got the right answer last night, I was so happy I forgot what I asked.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.