Why when I use "get_tree().change_scene_to(TheSceneI'mTryingtToGetTo)" it just restarts the scene?

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

So I’ve made a “Portal” type thing, that when the player enters it it changes scene.
Here’s the code for it. I’m using GDScript

extends Area2D

export var NextScene: PackedScene

func _on_Portal_body_entered(body):
if "Player" in body.name:

For some reason all this does is just restarts the scene, and I have changed “PackedScene” to the scene I want it to go to. Please help I have no clue why this is happening, I even tried copy and pasting somebody else’s code, and they said their code worked for them.

:bust_in_silhouette: Reply From: jgodfrey

So, a few things…

This line:

export var NextScene: PackedScene

… will have created a new Inspector slot named “Next Scene”. You need to physically drag the scene you want the script to load onto that inspector slot before running the scene.

Next, change your get_tree... line to this:


That will change to the scene represented by the NextScene object.