Alternative to func _ready for large number of nodes?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dodgyville


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):
      # next 2 lines same as placing my_script() inside scene._ready

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