#Applying variables to Instantiated Scene

8 messages · Page 1 of 1 (latest)

jaunty oyster
#

Is there any way to apply modified variables to an instantiated scene from the current scene?

For example, I have a Player scene and want to apply the changes I've made to the "View" variable while currently in a separate scene.

tacit aspen
#

Do you mean when you change scenes with SceneTree.change_scene_to_file/change_scene_to_packed? If that's the case, you can save the data when the _exit_tree() func is called and re-apply it again when the player is re-created in the new scene. To save the data you can create an autoload (aka singleton) to hold the data. See https://docs.godotengine.org/en/stable/tutorials/scripting/singletons_autoload.html

jaunty oyster
#

Not at runtime, but in the editor:

If i want to change the moveSpeed variable of a player, but do it from the Main Scene view and not the Player Scene view, is it possible to push those changes to the Player Scene?

#

as in, edit properties while in the Main Scene but have them save to the Player Scene

#

because currently the Player in the Main scene has its own unique properties

#

In Unity this is an "Apply Changes to Prefab" button

tacit aspen
#

Oh. No. There's no way to do that out of the box. Possibly neat idea for a plugin though.

What I do is make the changes in - say - the Player scene, rather than the Main scene. And by that I mean, changing the value in the Property Inspector for the player scene. The code for the exported property will still have the original value I defaulted it to. But when the player scene is instantiated from any other scene, that value I set in the Property Inspector will be used.

Does that make sense?

jaunty oyster
#

yes. so basically I just gotta adapt.