+3 votes

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 physicsprocess(delta):
var bodies = getoverlappingbodies()
for body in bodies:
if body.name == "Player":

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

in Engine by (15 points)

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.

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 :(

1 Answer

0 votes

I assume you got the code from this tutorial: https://www.youtube.com/watch?v=KzLfi0r4Muw

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.

by (50 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.