Godot 3 Tutorial: Switching Levels made Easy

Поділитися
Вставка
  • Опубліковано 29 вер 2024
  • This video goes over a basic yet dynamic system that can be used to automatically switch to the next level. Instead of hard coding every level in, this system uses level name conventions to it's advantage.
    Join the community Discord - / discord
    If you want to see more from me you can find it on my Twitter - / plug_world

КОМЕНТАРІ • 102

  • @davidphillips9366
    @davidphillips9366 4 роки тому +42

    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!

  • @dfa2691
    @dfa2691 3 роки тому +18

    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.

  • @AntonLeChuck
    @AntonLeChuck 4 роки тому +13

    Superb! Just as I was needing this information, I stumbled (and subbed) your videos! Thankyou

    • @PlugWorld
      @PlugWorld  4 роки тому +3

      No problem. Glad you are enjoying the videos!

  • @june_rain_video_game_company
    @june_rain_video_game_company 4 роки тому +13

    Dude. This is a genius. Thanks for sharing. Godot needs people like you

  • @cmds.learning7426
    @cmds.learning7426 4 роки тому +3

    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

  • @MacronLacrom
    @MacronLacrom 4 роки тому +10

    I thought you can only have a limited amount of scenes in a project.

    • @PlugWorld
      @PlugWorld  4 роки тому +16

      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.

  • @n.k.productions9614
    @n.k.productions9614 10 місяців тому +1

    Idk how any of this works, the collision doesnt work

  • @rtfranco
    @rtfranco 4 роки тому +2

    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?

  • @whythefaceatm2544
    @whythefaceatm2544 Рік тому +1

    this doesn't work in Godot 4.0, can you update this?

    • @PlugWorld
      @PlugWorld  Рік тому +1

      Just updated! ua-cam.com/video/GZrALMvOwY8/v-deo.html

  • @drdrub
    @drdrub 3 роки тому +4

    Thank you so much! I knew this was possible but didn’t know how!

    • @PlugWorld
      @PlugWorld  3 роки тому

      No problem, glad to help!

  • @Lkvvgfgfggdgb
    @Lkvvgfgfggdgb 3 роки тому +3

    Thank you mister so much. This is so quick help. Thank you . 👋👋👋

    • @PlugWorld
      @PlugWorld  3 роки тому +1

      Glad it was helpful for you 👍

  • @taoliu7312
    @taoliu7312 4 роки тому +3

    This is great ! ! After entering (+1) or exiting (-1), how to make the player's position beside the door?

    • @PlugWorld
      @PlugWorld  4 роки тому +1

      Can't you just change the player's position in the level? Or am I misunderstanding the question?

    • @Gakusangi
      @Gakusangi 3 роки тому +1

      @@PlugWorld there may be an instance where the player can enter a level from different directions. Think rooms in a dungeon from LoZ.

  • @Maltebyte2
    @Maltebyte2 Рік тому +1

    Thanks for this! is there a way to show via text like mario game so the player can see it top right?

  • @waterb-g9114
    @waterb-g9114 4 роки тому +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.

    • @PlugWorld
      @PlugWorld  4 роки тому +2

      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.

    • @roberoat596
      @roberoat596 3 роки тому

      @@PlugWorld i keep getting taken to Level_3 even on level 2

  • @yourkodi3945
    @yourkodi3945 4 роки тому +3

    Brilliant!

  • @benperrin1612
    @benperrin1612 3 роки тому +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? :)

    • @PlugWorld
      @PlugWorld  3 роки тому +3

      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.

    • @benperrin1612
      @benperrin1612 3 роки тому +4

      @@PlugWorld that fixed it, I forgot to number them in the scene tree, thanks a lot!

  • @monstereugene
    @monstereugene 2 роки тому +1

    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

    • @PlugWorld
      @PlugWorld  2 роки тому

      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.

  • @mrlonely420
    @mrlonely420 4 роки тому +2

    thanks man you really helped me out =)

  • @_Garm_
    @_Garm_ 4 роки тому +1

    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

    • @cmds.learning7426
      @cmds.learning7426 4 роки тому +1

      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

  • @chedev
    @chedev Рік тому

    uhh error Invalid type in 'int' constructor. Cannot convert argument 1 from StringName to String.

    • @weerkat
      @weerkat 3 місяці тому

      I have the same issue

  • @kaspiannilsen646
    @kaspiannilsen646 Рік тому +1

    Thanks for this tutorial. Really easy to follow and understand

  • @nicolasandrade7794
    @nicolasandrade7794 3 роки тому +1

    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?

    • @PlugWorld
      @PlugWorld  3 роки тому

      Is the player's hotbox under the Player group? Also check the collision layers and make sure they are all on the same layer.

  • @brutusmagnuson315
    @brutusmagnuson315 9 місяців тому

    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.

  • @ChUwU
    @ChUwU 3 роки тому +1

    this is the simplest tutorial about this i've seen :D

  • @Della_B
    @Della_B 3 роки тому +1

    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?

    • @PlugWorld
      @PlugWorld  3 роки тому

      Is the area entered signal actually connected to the script?

    • @Della_B
      @Della_B 3 роки тому +1

      @@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

    • @PlugWorld
      @PlugWorld  3 роки тому

      Is your player's hotbox in the "Player" group? Also sorry about the late reply, I thought I already replied.

  • @JeanVermeersch
    @JeanVermeersch 4 роки тому +7

    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? 🤔

  • @kimojumamil6121
    @kimojumamil6121 4 роки тому +2

    Very useful. Thank you :).

    • @PlugWorld
      @PlugWorld  4 роки тому +1

      No problem, thanks for watching :D

  • @mrdum7915
    @mrdum7915 2 роки тому

    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

  • @athsmooth2171
    @athsmooth2171 2 роки тому

    I have a weird issue. Mind to copy and paste to me?

  • @adrianluu3890
    @adrianluu3890 4 роки тому +1

    How do u make it if the player dies gets transition to the start of the level

    • @LeGiiTxKiDDs
      @LeGiiTxKiDDs 3 роки тому +1

      This is how i did it
      if health

  • @tobynuttall4354
    @tobynuttall4354 3 роки тому +1

    Thank you my man

  • @MistaSmith
    @MistaSmith Рік тому

    With modulo you can just go back to level 1 after level 2.

  • @manikandanu2317
    @manikandanu2317 2 роки тому

    Thanks a lot

  • @AkramSays
    @AkramSays 7 місяців тому

    LOVE

  • @elrz6139
    @elrz6139 3 роки тому

    to whom Hitbox is connected in 1:25
    I can't make it works...

  • @Covrse
    @Covrse Рік тому

    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.

    • @PlugWorld
      @PlugWorld  Рік тому

      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.

  • @noelvelic-manduric3399
    @noelvelic-manduric3399 3 роки тому

    Pls Can you Show me the Player Node and Script

  • @bigbraindev
    @bigbraindev Рік тому

    Best Video EVER........................
    where were you all this time

  • @garylake9317
    @garylake9317 3 роки тому

    What if you want to back a level

    • @PlugWorld
      @PlugWorld  3 роки тому

      Subtract one instead of adding one to the current level number.

  • @krasnavin
    @krasnavin 4 роки тому +1

    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?

    • @PlugWorld
      @PlugWorld  4 роки тому

      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.

    • @krasnavin
      @krasnavin 4 роки тому +1

      @@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
      @PlugWorld  4 роки тому

      Can you send me the error?

    • @krasnavin
      @krasnavin 4 роки тому

      @@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()

    • @krasnavin
      @krasnavin 4 роки тому +1

      I fixed it. In Player sprite tscn I added its Area2D in group Player.

  • @infernojoe
    @infernojoe Рік тому

    how can i do this in godot 4?

    • @PlugWorld
      @PlugWorld  Рік тому +1

      ua-cam.com/video/GZrALMvOwY8/v-deo.html

  • @MohamedSayedAbdElRaheem
    @MohamedSayedAbdElRaheem Рік тому +1

    perfect idea, i liked.

  • @zinhaboussi
    @zinhaboussi 4 роки тому

    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

  • @t3st3d
    @t3st3d Рік тому

    nice tutorial

  • @ollepettersson1869
    @ollepettersson1869 3 роки тому

    thank you

  • @oneonlykingdavid-gameserie2929
    @oneonlykingdavid-gameserie2929 3 роки тому +1

    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.

  • @jobro6144
    @jobro6144 3 роки тому

    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
      @PlugWorld  3 роки тому

      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.

    • @jobro6144
      @jobro6144 3 роки тому

      @@PlugWorld I will try that out and tell you how it goes

    • @jobro6144
      @jobro6144 3 роки тому

      @@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

    • @jobro6144
      @jobro6144 3 роки тому

      @@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.

  • @quae6843
    @quae6843 3 роки тому +1

    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.

    • @PlugWorld
      @PlugWorld  3 роки тому

      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.

  • @jeeb.3647
    @jeeb.3647 3 роки тому

    Thank you maaan

    • @PlugWorld
      @PlugWorld  3 роки тому

      Thanks for watching maaan

  • @jrotela
    @jrotela 4 роки тому +1

    ¿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

    • @PlugWorld
      @PlugWorld  4 роки тому +2

      Glad you enjoyed it.
      It's as easy as instead of adding 1 to the current level, subtract one and it should work.

  • @jamesxxxyz8775
    @jamesxxxyz8775 4 роки тому

    No next level should not cause an error, instead display "the end"... back to main menu option.

  • @NeZversSounds
    @NeZversSounds 4 роки тому

    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.

    • @NeZversSounds
      @NeZversSounds 4 роки тому +1

      @@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.

  • @bruns_tube
    @bruns_tube 3 роки тому +2

    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?

    • @PlugWorld
      @PlugWorld  3 роки тому +3

      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.

    • @bruns_tube
      @bruns_tube 3 роки тому +2

      @@PlugWorld Ah of course... I should have thought about that. Cheers mate. Thanks.

  • @whobitmyneck
    @whobitmyneck 4 роки тому +1

    You should've used .format(), it makes code look much better

    • @PlugWorld
      @PlugWorld  4 роки тому

      Not sure what you mean by .format() I am interested, care to explain it a bit more to me. I haven't heard of this.

    • @whobitmyneck
      @whobitmyneck 4 роки тому +1

      @@PlugWorld In python and gdscript there's a method for strings called format(), in gdscript, .format() takes two arguments, a list containing what will be substituted into the string, and the second argument being what exact string is going to be substituted. For example, "{} {} {}".format([1,2,3],"{}")

    • @PlugWorld
      @PlugWorld  4 роки тому

      @@whobitmyneck Awesome! Thanks for the explanation! I'll have to use that more.

    • @6Pope9
      @6Pope9 3 роки тому

      @@whobitmyneck But how would you do it when the index of the level is changing? It would not looked better.