Can't open another scene

Godot Version

Godot 4

Question

So, i am having problems with loading another scene in Godot 4.0 and it’s spesificly in level 2, and not level 1.I really have no idea why this is happening.

This is the code

extends Area2D

@export var next_scene: PackedScene

# Called when the node enters the scene tree for the first time.
func _ready():
	pass


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
	pass

func _on_body_entered(body):
	if (body.name == "player"):
		get_tree().change_scene_to_packed(next_scene)
		print("lksdflkj") #This is just here to debug. It does show up

If you need more detail just ask them :smile:

What kind of problem? Is there any error message?

1 Like

Hello! I figured out how to solve the issue and i don’t need help :slight_smile: The issue was that i was instead of using a (@export_file() ) i used the (@export) this is the code that works :smiley:

extends Area2D

@export_file() var next_scene

# Called when the node enters the scene tree for the first time.
func _ready():
	pass


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
	pass

func _on_body_entered(body):
	if (body.name == "player"):
		if next_scene:
			get_tree().change_scene_to_file(next_scene)

I am happy to figure this out, and i want to give a thanks to the top commenter on this video:

There are a couple it is:

E 0:00:00:0742 _parse_ext_resource: res://Scenes/Levels/Level_2.tscn:514 - Parse Error: [ext_resource] referenced non-existent resource at: res://Scenes/Levels/Level_1.tscn
<C++ Source> scene/resources/resource_format_text.cpp:163 @ _parse_ext_resource()

and:

E 0:00:40:0795 goal.gd:16 @ _on_body_entered(): This function can’t be used during the in/out signal.
<C++ Error> Condition “locked” is true.
<C++ Source> scene/2d/area_2d.cpp:328 @ _clear_monitoring()
goal.gd:16 @ _on_body_entered()

and:

E 0:00:40:0795 goal.gd:16 @ _on_body_entered(): Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead.
<C++ Source> scene/2d/collision_object_2d.cpp:98 @ _notification()
goal.gd:16 @ _on_body_entered()

and the last one is:

E 0:01:27:0392 goal.gd:16 @ _on_body_entered(): Can’t change to a null scene. Use unload_current_scene() if you wish to unload it.
<C++ Error> Condition “p_scene.is_null()” is true. Returning: ERR_INVALID_PARAMETER
<C++ Source> scene/main/scene_tree.cpp:1409 @ change_scene_to_packed()
goal.gd:16 @ _on_body_entered()