Godot Version
godot version 4.4.1 stable
Question
I’m working on a small 2d game, and currently I’m working with the scene changer. the idea of the code is, i can flag the two global variables from anywhere, and the scene changer script takes the data in the global variables and changes the scene. the reason im doing it from a node, and not using the root, is because i have a whole camera and shader setup that needs to be always loaded, and is set up so that as long as i have the scenes as child nodes, it works without any hiccups. my script is this.
extends Node2D
var instance
func _ready():
var scene = load(“res://assets/main/title.tscn”)
instance = scene.instantiate()
add_child(instance)
scene = null
func _physics_process(delta: float) → void:
if global.scene_change_check:
for child in self.get_children():
print(“clearing children”)
self.remove_child(child)
var scene = load(global.scene_change)
instance = scene.instantiate()
add_child(instance)
scene = null
global.scene_change_check = false
for the most part, it works perfectly, but the only issue is that when it calls that it cleared the child, the current scene stays, and the one its changing to is just slapped over it.