How to pass parameters to a scene when call change_scene

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

If I want to pass parameters to a scene before it is added to the scene tree by calling change_scene,how can I do?

:bust_in_silhouette: Reply From: Zylann

This was already asked: https://forum.godotengine.org/1883/transfering-a-variable-over-to-another-scene

There are various ways of doing it, mostly involving auto-loads.
But since changing scene is roughly the same as queue_free on the root then add_child another one, you can deduce quite a lot of ways of doing it.

I knew we can set a property of a node instance to pass parameter to that instance if we make the node instance by script code.
Since there is a change_scene API as a shortcut to change scene, I prefer to use this API,it seems it’s impossible to pass parameters to the new scene instance before it’s _ready function is called.

alexzheng | 2018-06-07 13:54

In my situation, I want to the new scene to show different content by the data passed to it.

alexzheng | 2018-06-07 13:59

Then either hide/show/instance different stuff in the next scene, or change to another scene, or don’t use change_scene.

Zylann | 2018-06-07 18:53