0 votes

Hi,

I know that I can attach a script to a scene node and use func _ready to do stuff after the node has entered the tree.

However I have a lot of 3D scenes I like to switch between. Is it possible to replicate the _ready function for a large number of scenes in one location?

eg something like:

func switch_node(scene):
      get_tree().change_scene(scene)
      # next 2 lines same as placing my_script() inside scene._ready
      wait_until_ready()  
      my_script()

I ask because I have a lot of scenes and don't want to create a script for each one if possible.

in Engine by (204 points)

It depends on what is it that you are doing in the my_script function. If the scenes have the same behaviours (and are the same kind of node) then you could just create 1 script with the _ready function logic and attach that same script to every 3D scene.

I think that's the way to go, thanks for the suggestion!

Please log in or register to answer this question.

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.