0 votes

So for my game i've got one main scene where i then instantiate the other scenes to it (like the main menu and all the levels) and the player scene is instantiated in the other scenes (not through code) that get added to the main scene. Would the _ready() function on the players script get called when i swap scenes (levels)? To clarify, if i remove the current levels scene and add another one that also has the player scene in it would the players _ready() function get called again?

Godot version stable mono 3.4.4
in Engine by (34 points)

I believe the _ready function would be called again, yes. However, if I understand your situation correctly, it's important to realize that although the _ready function in the player's script will be called multiple times, from a player instance point of view, individual player instances' _ready function will only be called once, since you are creating multiple player instances assuming each stage defines it's own player.

I believe that moving (via code) the player from one level to the next would not trigger the _ready function to be called twice, but I may be wrong on this point.

A tip, for future - for this and other similar questions.

Just throw a print statement in ready()_ and try it. Do you see your message output each time you load a new scene? Or, similarly, set a debug breakpoint in _ready(). Does it get hit each time you load a new scene?

1 Answer

0 votes
Best answer

Yes, every ready will be called when new scene is is instantiated, along with its children. Take a note, that despite every level having a childed player node, these are not the same player nodes. They are different instances of one scene, they have different IDs. And this is pretty much why their ready is called.
Because when a node with certain ID gets removed from the tree, the next time it is childed, its ready is not called ! It will then require request_ready to call ready once more.

by (7,305 points)
selected by
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.