Need help with level changing in a platformer

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

Hello guys Im an absolute beginner making his first game in Godot. Im making a platformer akin to the style of Super Mario Bros, with an object at the end of the level to take you to the next level.

I had this script found online and it worked for between world.tscn and world2.tscn but now that i added World3.tscn it wont work, instead of taking me there when i complete world 2 it takes me back to world 1. Here is the current code (job is the level changing object):
extends Area2D

export(String, FILE, “*.tscn”) var next_world

func _physics_process(delta):
var bodies = get_overlapping_bodies()
for body in bodies:
if == “Player”:

immense thanks to anyone who could help me with this!!

Are you trying to persist nodes through different scenes?

Instead of using change_scene(), you should probably go with a root node design pattern, where all scenes are children of a regular Node, rather than a Viewport. This way, scenes can be managed easier. Node persistence is easier this way as well.

Kyle Guarco | 2019-04-21 03:25

How could I do that? I’m quite the noobie but I’d appreciate if you could show me how I could solve my problem with the alternative you proposed, I have no idea how to do it :frowning:

buddyhoodie | 2019-04-21 04:18

:bust_in_silhouette: Reply From: Kaligule

I assume you got the code from this tutorial:

You go to your world2.tscn and select the exitportal. In the right corner you can see the inspector and (you might have to click on the inspector to see this) a script variable called next_world. This is here because you exportet this variable in your script, meaning that you allowed this variable to be edited in the Godot GUI.

From what you wrote I understand that this variable is currently set to world.tscn. You should set it to World3.tscn. Thats all, your “portal” now points to the 3rd level.