0 votes

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.

asked Apr 17 in Engine by RowingNoob (20 points)

1 Answer

0 votes

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.

answered Apr 17 by jgodfrey (5,674 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.