I've tryed to make a pokemon-like some time ago and implemented like this:
I created a scritp called Global and put on autoload.
here is the script:
extends Node
var root
var world_scene
func _ready():
root = get_tree().get_root()
func change_to_battle(path: String, enemy: Enemie):
var new_scene_res = load(path)
var new_scene = new_scene_res.instance()
new_scene.set_enemy(enemy)
world_scene = get_tree().get_current_scene()
root.add_child(new_scene)
get_tree().set_current_scene(new_scene)
root.remove_child(world_scene)
func back_to_world():
world_scene.back_to_world()
root.remove_child(get_tree().get_current_scene())
root.add_child(world_scene)
get_tree().set_current_scene(world_scene)
The back_to_world
is just a method that I used to do some things when the player comes back like remove the enemy of the scene.
The arg path
contais the path to the battle scene and the arg enemy
contain the data of the enemy for battle.
Whent the player collides on enemy just call Global.change_to_battle(...)
P.S.: That code makes the scene of level continue in the memory and consuming memory. For sure that is not the best way, but is the easyest way that i found when i coded the project...