Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | dodgyville |
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.
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.
quijipixel | 2018-02-05 11:39
I think that’s the way to go, thanks for the suggestion!
dodgyville | 2018-02-06 02:11