Issue teleporting between scenes

Godot Version

4.1

Question

I’m just starting to learn game dev and I’ve been following a youtube tutorial to make a basic 2D platformer game. Everything has worked fine except for one small problem I can’t seem to figure out.

I have a main menu and two levels. When the player touches the trophy in level 1, they should teleport to level 2. When they touch the trophy in level 2, they should teleport back to the main menu.

So far, I have main menu buttons that teleport to each level that work fine. The trophy also works teleporting from level 1 to 2, but not level 2 to the main menu.

I have the trophy and its collision box saved as a subscene so that I can easily pull it into each level.

This is the script that the tutorial attached to that subscene so that I can select the target scene in the inspector (because hard coding the scene won’t work when I am using the same object for multiple purposes):

@export var target_level:PackedScene

func _on_body_entered(body):
	if (body.name == "CharacterBody2D"):
		get_tree().change_scene_to_packed(target_level)

For the level 1 trophy, I have the target scene selected as level 2 (shown on the right side in the inspector):

For the level 2 trophy, I have the target scene selected as the main menu

Even though this is the case, when playing level 2 the teleport doesn’t work, the character just walks in front of the trophy.

I even tried making the level 1 trophy teleport to the main menu and it worked, so I’m really confused as to why it’s not working in the second level.

Any clarification or help would be really appreciated!

When reaching the teleport point from area 2, check in the remote tab if the character is named CharacterBody2D

Looks like it is:

Check the collisions set to the area2d

All of the collision settings seem to be default:

I deleted the script and retyped it and everything works now. Not sure what the issue was.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.