SceneTree.change_scene() using a NodePath?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Payotz
:warning: Old Version Published before Godot 3 was released.

So, I have two scenes. Second scene is a minigame, and first scene is the normal game.

I want to change_scene() to the minigame, and after the minigame finishes, go back to the last scene.

I’ve been using get_tree().get_current_scene().get_path() and storing it to a global Singleton.
[global.lastScene]

The problem is, it’s a nodepath, and it doesn’t change_scene.

I tried storing get_tree().get_current_scene() into the singleton and switch to it using get_tree().set_current_scene() but for some reason, it doesn’t switch to it.

Printing global.lastScene causes it to crash.

So, how do I change_scene() using a NodePath?

:bust_in_silhouette: Reply From: eons

There are many ways to do it.

The way you do it is limited to what SceneTree offer, in this case you can add the “new current scene” to the root (needs to be a child) and make the tree do set_current_scene with it, then remove the child you want to keep away (it will stay processing while on the tree).

I would prefer to have a single scene as current scene (maybe a Node) that adds and remove children, it can take care of transition effects and things like that too.

I can think of playing with viewports and cameras too if you want all the scenes on the tree.

This is actually a great idea! Thank you very much!

Payotz | 2017-04-08 07:58