That's a really clever approach, I would have just exported a variable and then manually entered it each time I put it in a new level. With this approach and consistent naming it's just one less thing to have to worry about!
The current level should hold an export variable with the path to the desired scene, named "NextLevelScene". You could also attach a setget calls to have next level change dinamically based on palyer choices in game. This way you can also reorganise your scenes and the editor will update the paths and names consistent. Job done.
i haven't finished this work,but i think can we make a main scene never queuefree,then load sublevel to a subnode and change levels,like unreal's level streaming
This saved me hours of screwing around. Sometimes, you just need a simple tutorial. 🙂 You could also store the path as a string and use a @export variable so you can change as you go. If you’re making a non-linear game, it helps a lot. I know a lot of people like making top-down open world games.
Clever tutorial. Let's say the Player pick an item like a key in level_1 and goes to level_2, but later he returns to level_1. What is the best approach to say to level_1 that the Player already has the key or another items from there or that some chest was already open? Search into the Player inventory before load the items of the level_1?
You can create as many scenes as you want. As long as you have enough storage, but they take up very little space per scene. You shouldn't have to worry about it.
liked and subbed praise today's godot jesus edit: in practice I failed the player's code is basic movement and func ready : add to group "player" your code is directly copied no errors doesn't work
It's not always the code. You can copy the code word for word but that doesn't mean it will work. The biggest thing is making sure to connect your signals. Make sure you connect the next_level cube hitbox signals to itself. Copying in the code is not sufficient. Anyways let me know if you have anymore questions.
Well, I have some experience with GMS2 and I did the level transition (for non-linear game) like this: -Level has one or more "exits" with invisible collisions, -Every time the player enters a level exit collision, the player will read the data of entered exit, -Basing on read data, the player goes to the the level indicated in the exit and instantly places itself at indicated coordinates. Coordinates are needed to place the player at right position in order to make transition look more natural. By the way, GM Language is much easier than GD Script.
This tutorial was just focused on linear level switching, because that's what most people just need. But I am glad you are sharing your solution for others that are interested. I have used GMS 1.4 before. I would agree that game maker is more simple than Godot in terms of code. But I don't find Godot that much more complicated, a lot of times I have actually found Godot easier, but that may vary from 1.4 to 2.
I attempted to use this code with my 3D project and all it does is move from my Test_Level to Level_1 and then forever loops on Level_1, or if it's on Level_1 it just loops restarting Level_1. The only difference is that I'm using body_entered rather than area_entered. I attempted a bunch of changes to try and make it work, but it's looking like I'm still going to have to use a global script or something since it doesn't work.
Hi, I've inserted the code as you've done however instead of adding 1 to the level number (e.g. level_1 + 1 = Level_2) it just keeps reloading Level_1 on collision. I've checked the print in the console and it's definitely loading Level_1 every time no matter what current level you're in - any chance of some help? :)
Interesting, it's hard to say what the issue is without much info. Maybe it's what you named the scene, make sure that both your level 1 scene has one in the scene name both in the scene tree and in the tscn file. Do the same for level 2. If it's still not working, or that's configured correctly let me know.
hello, i've went through this tutorial and copied the code you've written exactly, no typos, no indent issues. Yet i'm getting and error on line 5 that says that the function change_scene returns a value but is never used, i've came across this error so many times and it's getting in the way of development.
It's just a warning, you can ignore it. It basically means that the function is generating data that isn't being used. You can disable warnings if you want.
im having trouble with the thing im working with a score thing and im making it so if you have 5 score the scene changes and it keeps changing the scene how do i make it only happen once
@@PlugWorld yeah, I have done that (connecting the hit box [area entered] to the sprite [Next level] scene) I also double check the code. I set the player collision to layer 1 and the mask to layer 1, meanwhile the next level scene collision same as the player
im new and confused to Godot. i understand the loading in a .tscen from the local resources... but im not sure about the Scene, i thought that it had to be in the scene hierarchy, where you have for example: world -> level1 ->level2 and each lever will have its own like Level1 -> Player , the level changer.. if possible could you make a video or if there is a video about it to point me in the right direction :D thank you for the help
that's a nifty one, thank you so much! :) I was thinking about something similar without finding the right script for it. I guess you could do the same to go back to previous scene, but with -1 instead of +1? 🤔
I followed everything in this tutorial but my player still does not seem to enter the next level, I need help in this. It may be because of my hitbox, but I am not sure what I have done wrong.
@@PlugWorld i think the problem is that my player is not colliding with the object that takes it to the next level, I am having trouble trying to fix that.
I copied your code but not going to next level. Must Hitbox be in group Player or just the sprite Player? I s there particular script in your Player.gd code?
Try doing both, I believe I did it just for the hitbox of the player. And you are correct if it's not changing levels it's probably the collision code, other wise you would be getting an error. If you need more help with it let me know. Or just @ me on Discord whatever works for you.
@@PlugWorld Line 3 I did not have and made a signal but get error and no level change. For my player sprite I have childs: area2d & collisionshape2d. Player sprite has script only to move.
@@PlugWorld E 0:00:06.361 emit_signal: Error calling method from signal 'area_shape_entered': 'Sprite(Next_level.gd)::_on_Hitbox_area_shape_entered': Method expected 1 arguments, but called with 4.. core/object.cpp:1260 @ emit_signal()
Hi, I am beginner in Godot, and I recently made 7 level game and made them separately, so that problem now is how to connect them under one game. First problem is this: I made one level as level_2 folder and inserted it to the level_1, but it is not appearing inside engine. So it seems big problem, or how to fix this, simplest tutorial please. Thank you.
A neat way to make it dynamic. But as the tutorial, I think it was presented too sophisticated for noobies. You should have stuck to a multi-line readable explanation.
@@PlugWorld I mean it is a good technique but presented in a sophisticated way - one-liner. I think if it was divided into several lines it would be easier to digest. For tutorials try to write in a readable manner (step by step). It helps a lot.
I've done exactly the same as you, here's my line of code that changes the scene. get_tree().change_scene("res://Scenes/Levels/Chapter_1_Level_" + str(int(get_tree().current_scene.name) + 1) + ".tscn") When I print it like you did then it prints Level_12. Why is not taking the 1 from Level_1 away?
It's probably because in your name of the level (depends on the scene name not the file name) you have it set to Chapter_1_Level_2 (I am guessing) Now when it converts it into an int it takes the 1 and the 2 and puts them together which gives you 12. So that's the problems with this approach is that you can't have any other numbers in your scene name or it throws it off. But you could do some string functions just to tell Godot to look at the very end of the string then convert that to int, that would fix it.
That's a really clever approach, I would have just exported a variable and then manually entered it each time I put it in a new level. With this approach and consistent naming it's just one less thing to have to worry about!
Superb! Just as I was needing this information, I stumbled (and subbed) your videos! Thankyou
No problem. Glad you are enjoying the videos!
The current level should hold an export variable with the path to the desired scene, named "NextLevelScene".
You could also attach a setget calls to have next level change dinamically based on palyer choices in game.
This way you can also reorganise your scenes and the editor will update the paths and names consistent.
Job done.
Dude. This is a genius. Thanks for sharing. Godot needs people like you
Thank you so much! I knew this was possible but didn’t know how!
No problem, glad to help!
Thanks for this tutorial. Really easy to follow and understand
Thank you mister so much. This is so quick help. Thank you . 👋👋👋
Glad it was helpful for you 👍
This is a smart way and explained very well, thank you, I will try this
Best Video EVER........................
where were you all this time
this is the simplest tutorial about this i've seen :D
Brilliant!
Very useful. Thank you :).
No problem, thanks for watching :D
i haven't finished this work,but i think can we make a main scene never queuefree,then load sublevel to a subnode and change levels,like unreal's level streaming
perfect idea, i liked.
glad it was helpful 👍
thanks man you really helped me out =)
This saved me hours of screwing around. Sometimes, you just need a simple tutorial. 🙂
You could also store the path as a string and use a @export variable so you can change as you go. If you’re making a non-linear game, it helps a lot. I know a lot of people like making top-down open world games.
Clever tutorial. Let's say the Player pick an item like a key in level_1 and goes to level_2, but later he returns to level_1. What is the best approach to say to level_1 that the Player already has the key or another items from there or that some chest was already open? Search into the Player inventory before load the items of the level_1?
Thank you my man
I thought you can only have a limited amount of scenes in a project.
You can create as many scenes as you want. As long as you have enough storage, but they take up very little space per scene. You shouldn't have to worry about it.
liked and subbed
praise today's godot jesus
edit: in practice I failed
the player's code is basic movement and func ready : add to group "player"
your code is directly copied no errors doesn't work
It's not always the code. You can copy the code word for word but that doesn't mean it will work. The biggest thing is making sure to connect your signals. Make sure you connect the next_level cube hitbox signals to itself. Copying in the code is not sufficient.
Anyways let me know if you have anymore questions.
Well, I have some experience with GMS2 and I did the level transition (for non-linear game) like this:
-Level has one or more "exits" with invisible collisions,
-Every time the player enters a level exit collision, the player will read the data of entered exit,
-Basing on read data, the player goes to the the level indicated in the exit and instantly places itself at indicated coordinates. Coordinates are needed to place the player at right position in order to make transition look more natural.
By the way, GM Language is much easier than GD Script.
This tutorial was just focused on linear level switching, because that's what most people just need. But I am glad you are sharing your solution for others that are interested.
I have used GMS 1.4 before. I would agree that game maker is more simple than Godot in terms of code. But I don't find Godot that much more complicated, a lot of times I have actually found Godot easier, but that may vary from 1.4 to 2.
This is great ! ! After entering (+1) or exiting (-1), how to make the player's position beside the door?
Can't you just change the player's position in the level? Or am I misunderstanding the question?
@@PlugWorld there may be an instance where the player can enter a level from different directions. Think rooms in a dungeon from LoZ.
Can u tell the asset pack from the thumbnail? Loooks so good and would be perfect for a first simple platformer project. Or is it self made?
awesome tutroail , please keep sharing this kind of videos short and effictive and you can share with us your patreon to support you , have a good day
Thanks for this! is there a way to show via text like mario game so the player can see it top right?
I attempted to use this code with my 3D project and all it does is move from my Test_Level to Level_1 and then forever loops on Level_1, or if it's on Level_1 it just loops restarting Level_1.
The only difference is that I'm using body_entered rather than area_entered.
I attempted a bunch of changes to try and make it work, but it's looking like I'm still going to have to use a global script or something since it doesn't work.
Interesting, it shouldn't be different in 3d. Make sure you are adding 1 to the current level or it will keep restarting the same level like you said.
@@PlugWorld i keep getting taken to Level_3 even on level 2
Hi, I've inserted the code as you've done however instead of adding 1 to the level number (e.g. level_1 + 1 = Level_2) it just keeps reloading Level_1 on collision. I've checked the print in the console and it's definitely loading Level_1 every time no matter what current level you're in - any chance of some help? :)
Interesting, it's hard to say what the issue is without much info.
Maybe it's what you named the scene, make sure that both your level 1 scene has one in the scene name both in the scene tree and in the tscn file. Do the same for level 2.
If it's still not working, or that's configured correctly let me know.
@@PlugWorld that fixed it, I forgot to number them in the scene tree, thanks a lot!
hello, i've went through this tutorial and copied the code you've written exactly, no typos, no indent issues. Yet i'm getting and error on line 5 that says that the function change_scene returns a value but is never used, i've came across this error so many times and it's getting in the way of development.
It's just a warning, you can ignore it. It basically means that the function is generating data that isn't being used. You can disable warnings if you want.
im having trouble with the thing im working with a score thing and im making it so if you have 5 score the scene changes and it keeps changing the scene how do i make it only happen once
this doesn't work in Godot 4.0, can you update this?
Just updated! th-cam.com/video/GZrALMvOwY8/w-d-xo.html
when i try to enter the next level, the player won't colide with it (i already followed the code and the nodes) what should i do?
Is the area entered signal actually connected to the script?
@@PlugWorld yeah, I have done that (connecting the hit box [area entered] to the sprite [Next level] scene) I also double check the code.
I set the player collision to layer 1 and the mask to layer 1, meanwhile the next level scene collision same as the player
Is your player's hotbox in the "Player" group? Also sorry about the late reply, I thought I already replied.
whenever I try to go onto it doesn't collide and I have the collision shape2d and the hitbox and the sprite could someone lend me a hand, please?
Is the player's hotbox under the Player group? Also check the collision layers and make sure they are all on the same layer.
im new and confused to Godot. i understand the loading in a .tscen from the local resources... but im not sure about the Scene, i thought that it had to be in the scene hierarchy, where you have for example: world -> level1 ->level2 and each lever will have its own like Level1 -> Player , the level changer.. if possible could you make a video or if there is a video about it to point me in the right direction :D thank you for the help
everything can be a scene in godot(in my opinion),like level map,musicplayer,shader...but how to managment and use them need to have a good idea
Idk how any of this works, the collision doesnt work
uhh error Invalid type in 'int' constructor. Cannot convert argument 1 from StringName to String.
I have the same issue
Thank you maaan
Thanks for watching maaan
to whom Hitbox is connected in 1:25
I can't make it works...
that's a nifty one, thank you so much! :) I was thinking about something similar without finding the right script for it. I guess you could do the same to go back to previous scene, but with -1 instead of +1? 🤔
yes you could
With modulo you can just go back to level 1 after level 2.
nice tutorial
How do u make it if the player dies gets transition to the start of the level
This is how i did it
if health
I followed everything in this tutorial but my player still does not seem to enter the next level, I need help in this. It may be because of my hitbox, but I am not sure what I have done wrong.
Make sure that the Area2D on your player is in the group "Player" and make sure that your scene files have a number that matches the level number.
@@PlugWorld I will try that out and tell you how it goes
@@PlugWorld I dont get what you mean Area2D is in the group "Player". Im pretty new to Godot so I'm not sure what you exactly mean by that
@@PlugWorld i think the problem is that my player is not colliding with the object that takes it to the next level, I am having trouble trying to fix that.
I copied your code but not going to next level. Must Hitbox be in group Player or just the sprite Player? I s there particular script in your Player.gd code?
Try doing both, I believe I did it just for the hitbox of the player. And you are correct if it's not changing levels it's probably the collision code, other wise you would be getting an error. If you need more help with it let me know. Or just @ me on Discord whatever works for you.
@@PlugWorld Line 3 I did not have and made a signal but get error and no level change. For my player sprite I have childs: area2d & collisionshape2d. Player sprite has script only to move.
Can you send me the error?
@@PlugWorld E 0:00:06.361 emit_signal: Error calling method from signal 'area_shape_entered': 'Sprite(Next_level.gd)::_on_Hitbox_area_shape_entered': Method expected 1 arguments, but called with 4..
core/object.cpp:1260 @ emit_signal()
I fixed it. In Player sprite tscn I added its Area2D in group Player.
What if you want to back a level
Subtract one instead of adding one to the current level number.
LOVE
thank you
Thanks a lot
I have a weird issue. Mind to copy and paste to me?
never mind, fixed it
Pls Can you Show me the Player Node and Script
¿What should i do if i want to use the same "level changing" to back from level 2 to level 1 again?
Pd: Good video
Glad you enjoyed it.
It's as easy as instead of adding 1 to the current level, subtract one and it should work.
how can i do this in godot 4?
th-cam.com/video/GZrALMvOwY8/w-d-xo.html
No next level should not cause an error, instead display "the end"... back to main menu option.
Hi, I am beginner in Godot, and I recently made 7 level game and made them separately, so that problem now is how to connect them under one game. First problem is this: I made one level as level_2 folder and inserted it to the level_1, but it is not appearing inside engine. So it seems big problem, or how to fix this, simplest tutorial please. Thank you.
A neat way to make it dynamic. But as the tutorial, I think it was presented too sophisticated for noobies. You should have stuck to a multi-line readable explanation.
@@PlugWorld I mean it is a good technique but presented in a sophisticated way - one-liner. I think if it was divided into several lines it would be easier to digest.
For tutorials try to write in a readable manner (step by step). It helps a lot.
I've done exactly the same as you, here's my line of code that changes the scene.
get_tree().change_scene("res://Scenes/Levels/Chapter_1_Level_" + str(int(get_tree().current_scene.name) + 1) + ".tscn")
When I print it like you did then it prints Level_12. Why is not taking the 1 from Level_1 away?
It's probably because in your name of the level (depends on the scene name not the file name) you have it set to Chapter_1_Level_2 (I am guessing) Now when it converts it into an int it takes the 1 and the 2 and puts them together which gives you 12.
So that's the problems with this approach is that you can't have any other numbers in your scene name or it throws it off.
But you could do some string functions just to tell Godot to look at the very end of the string then convert that to int, that would fix it.
@@PlugWorld Ah of course... I should have thought about that. Cheers mate. Thanks.