Background Loading & Loading Screens | Godot 4

Sdílet
Vložit
  • čas přidán 23. 08. 2024
  • A quick guide on how to load scenes in the background and show a loading screen in Godot 4!
    #godot #gameengine #tutorial #gamedeveloper #gamedev #loading #scene

Komentáře • 107

  • @albiceleste101
    @albiceleste101 Před 10 měsíci +32

    The aesthetics and color scheme are gorgeous

  • @deadrats6781
    @deadrats6781 Před 11 měsíci +34

    Great tutorial. Thank you. I only wish example code were a bit bigger. :) Specially when on second part of the screen is just 0% most of the time

    • @JumboGamedev
      @JumboGamedev  Před 11 měsíci +7

      Thank you for the feedback, much appreciated!
      I will try to do better for future tutorials : )

  • @FPLogistic
    @FPLogistic Před 6 měsíci +6

    Quick and short, well edited, has all the info I needed to know. Just perfect! Thank you so much and I hope you can upload more often because your videos are really amazing

    • @JumboGamedev
      @JumboGamedev  Před 6 měsíci +1

      Thank you very much! I am planning to upload more.

  • @sergeantsapient
    @sergeantsapient Před 2 měsíci +1

    This was very useful and packed with a lot of info in under 3 minutes.

  • @evethedwarf
    @evethedwarf Před 8 měsíci +6

    Short and to the point. Love it and subscribed! :)

  • @darksoulcreeper7954
    @darksoulcreeper7954 Před měsícem

    This tutorial is genuinely one of the best if not the best I've ever experienced. Yeah the code viewport should have been larger. But Very nice.

  • @ClutchMonkey
    @ClutchMonkey Před měsícem

    The most efficient tutorial I have ever watched. Subscribed and Bell on.

  •  Před 3 měsíci

    Found one of your videos yesterday and have started to binge watch your channel. I like your aesthetic very much, and the short explanatory video format is very good for when you need fast instructions.

  • @Speed-TV
    @Speed-TV Před 6 měsíci +2

    Thank you so much! I'm so glad to finally be able to have loading screens, I'm definitely saving this code!

  • @gouldghost
    @gouldghost Před měsícem

    So simple, worked first try. Thank you!

  • @ProrokLebioda
    @ProrokLebioda Před 4 měsíci

    Clean, quick, concise! Great video! Just the short tip I needed to add loading screen! One for pause menu was useful as well!

  • @bitbraindev
    @bitbraindev Před 10 měsíci +4

    Extremely useful. I will definitely add this to my game, too.

  • @gamingxrelic
    @gamingxrelic Před 10 měsíci +2

    Such an outstandingly made video. Great job and thank you for explaining it so clearly!

  • @ThatSommeS
    @ThatSommeS Před 10 měsíci +2

    Thank you! Great tutorial with a very clear and accurate delivery

  • @Aratonati
    @Aratonati Před 6 měsíci +1

    Thanks so much! I was wondering how loading would work.

  • @AJMarraffa
    @AJMarraffa Před 3 měsíci

    Thank you so much, I was really confused on how to get this process started. My code was close but wasn't working, this helped me adjust it so it worked :)

  • @kiryonnakira7566
    @kiryonnakira7566 Před 2 měsíci

    short, clear, and clean. Thanks man

  • @kyuos
    @kyuos Před 3 měsíci

    One of the Best explainations how it works. Keept it up!

  • @psycho_ocelot
    @psycho_ocelot Před 3 měsíci

    The video is very useful and your video editing is very good. Keep up the good work.

  • @tejaswithme3713
    @tejaswithme3713 Před 4 měsíci

    Great tutorial brother!
    Love from India ❤

  • @TheRealAfroRick
    @TheRealAfroRick Před 9 měsíci

    Very clearly explained. Gonna wrap this into some UI components for my game this afternoon.

  • @meraklmuskulpesent8313
    @meraklmuskulpesent8313 Před rokem +3

    Great tutorial. Keep up the good work.

  • @antimari22
    @antimari22 Před rokem +1

    welcome back

  • @sapbucry
    @sapbucry Před 10 měsíci

    Awesome, keep em coming!

  • @Erwjable
    @Erwjable Před 9 měsíci

    Excellent explained, thanks!

  • @suthamonhengrasmee8182
    @suthamonhengrasmee8182 Před 10 měsíci

    Great tutorial. Thank you.

  • @proevilz
    @proevilz Před 6 měsíci

    Damn you sound like a calm Jon Zherka

  • @morganp7238
    @morganp7238 Před měsícem

    subbed and liked, thanks

  • @MohamedSamy-vp2pq
    @MohamedSamy-vp2pq Před 9 měsíci

    best channel ever

  • @simonsaysgray
    @simonsaysgray Před 8 měsíci

    Thank you, works very well! For some reason, it jumps from 0.4 to 1.0, but maybe it's just the scene i'm loading...

  • @UnstoppableTigra
    @UnstoppableTigra Před rokem +1

    Hey, good to see new video from u. Is it new thing background loading implemented in last versions? or it was here long time?

    • @JumboGamedev
      @JumboGamedev  Před rokem +1

      Hey, thank you!
      Yes, it is a new way to do background loading added in Godot 4 ( github.com/godotengine/godot/pull/36640 )

  • @morganstrauss8516
    @morganstrauss8516 Před rokem

    Nice tuts!! thanks!

  • @Mik-kv8xx
    @Mik-kv8xx Před rokem

    Yoooo look who's back

  • @DemKartal
    @DemKartal Před 9 měsíci +4

    In this example you are using get_tree().change_scene_to_packed(newScene) which automatically unloads every other scene. Is there a way to make it work with get_tree().root.add_child(newScene)? (That one throws an error, saying it cannot handle a PackedScene. Consider "sceneName" holding a path like in your example.)
    In my case it is not desirable to have everything unloaded... or is it a better approach to push everything which is supposed to be available (almost) permanently into global/autoload?

    • @DemKartal
      @DemKartal Před 9 měsíci +5

      I think I figured it out:
      loaded_scene = ResourceLoader.load_threaded_get(saved_path)
      var scene = loaded_scene.instantiate()
      get_tree().root.add_child(scene)
      Please correct me if I am wrong!

    • @JumboGamedev
      @JumboGamedev  Před 9 měsíci +4

      ​@@DemKartal You are absolutely correct!
      - A packedScene is an object that represents a scene. We can think of it as an object that contains all the information needed to instantiate/duplicate the nodes in this scene. So a packedScene is like a tree template, and we can invoke instantiate() to clone this structure.
      - When we invoke the instantiate() method on a packedScene, we get a new scene instance, and the instantiate method returns the root node of this structure.
      - add_child expects a node as an argument, so this is why it didn't work at first.
      I hope this helps!

    • @DemKartal
      @DemKartal Před 9 měsíci +1

      @@JumboGamedev Thank you for confirmation and the detailed explanation!

    • @JumboGamedev
      @JumboGamedev  Před 9 měsíci

      @@DemKartal You are very welcome!

  • @AlvaroLand
    @AlvaroLand Před 7 dny

    Excellent video. Do you know if background loading is possible with single thread mode? Now that the web export has this single thread option many people like me will use it to avoid problems with the browsers but I can't find a way to load scenes without freezes.

    • @JumboGamedev
      @JumboGamedev  Před 4 dny +1

      The documentation of 4.3 for background loading is: docs.godotengine.org/en/stable/tutorials/io/background_loading.html#background-loading
      And it doesn't specifically mention your use case.
      If you want to do background loading on the main thread without freezes, I think you will have to interleave the execution of the game and loading the resource. You can manually read the file in small chunks during each frame (e.g., in the _process() function). This will reduce the risk of blocking the main thread. Consider using `get_buffer()`. docs.godotengine.org/en/stable/classes/class_fileaccess.html#class-fileaccess-method-get-buffer
      You can adjust the length as needed. After that you will have the file content, and you can load them as a resource. Hopefully, this will work!

    • @AlvaroLand
      @AlvaroLand Před 4 dny

      @@JumboGamedev Thank you, I will try that!

  • @noodledealer7447
    @noodledealer7447 Před 4 měsíci

    Goated

  • @delalexofficial
    @delalexofficial Před 5 měsíci

    Perfect! + sub

  • @ilsukketto
    @ilsukketto Před měsícem

    How do I increase the loading time by, say, 5 seconds after the scene has finished loading?

    • @JumboGamedev
      @JumboGamedev  Před měsícem

      You can use a Timer node, and use the timeout signal. Then, you can set the wait_time, and start the timer. docs.godotengine.org/en/stable/classes/class_timer.html

  • @gnomemann6986
    @gnomemann6986 Před 7 měsíci

    Very useful, but I have one question. If I wanted to use this function but make the loading wait for a function in the next scene to be run how would i do that?

    • @JumboGamedev
      @JumboGamedev  Před 6 měsíci

      If you want to run a function before switching to the new scene, you can run this function before the line `get_tree().change_scene_to_packed(newScene)`.

  • @ZurtPIZZA
    @ZurtPIZZA Před 19 dny

    Hola, no se mucho ingles pero quisiera que me asesoren. Cuando testeo mi juego en mi PC todo funciona, las instancias, las escenas, todo, el problema es cuando oo exporto a android. Algumas veces no entra al juego, otras veces se queda atascado en el menu principal y ahora que aplique este tutorial el resource loader me lanza un 2, que siignifica que hubo un error. No se que es exactamente soy principiante en esto y no quiero abandonarlo por un bug confuso

    • @JumboGamedev
      @JumboGamedev  Před 12 dny +1

      Hello!
      Some possible reasons to consider:
      - Make sure that you have the correct path to the resource. For example, ensure that the paths use `/` as the separator instead of `\`.
      - Mobile devices usually have less memory available (compared to PC). If your game uses a lot of resources, you might run out of memory, causing resources to fail to load. Maybe try to reduce the size of the textures, models, or other resources, if they are large.

  • @MrGold-zn1xo
    @MrGold-zn1xo Před 9 měsíci +1

    What determines a scene being finished loading? i have a scene with procedurally generated a world, but is that scene immediately "loaded", while the generation still continues to happen?

    • @JumboGamedev
      @JumboGamedev  Před 9 měsíci +1

      When we talk about a scene being loaded, we are generally referring to the process of taking a scene file (like .tscn) from the disk and bringing it into memory. This way we can interact and instantiate the scene. If you have scripts attached to a node in your scene that perform procedural generation when the scene starts up, that logic will execute after the scene is instantiated from the loaded data.

    • @MrGold-zn1xo
      @MrGold-zn1xo Před 9 měsíci +1

      @@JumboGamedev Thank you! That's what I thought. Do you know would I add a loading bar in my case?

    • @JumboGamedev
      @JumboGamedev  Před 9 měsíci +1

      @@MrGold-zn1xo Yes, I think it is a good idea to add a loading bar.

  • @fidgety48
    @fidgety48 Před 5 měsíci

    my game still freezes when this process happens? it may have something to do with the fact that im using an autoloaded object but im not sure

    • @JumboGamedev
      @JumboGamedev  Před 5 měsíci

      If your game freezes at some point, this likely means that there is some operation that blocks the main loop. It doesn't have to be the autoload.

    • @fidgety48
      @fidgety48 Před 5 měsíci

      @@JumboGamedevthe mistake was that i compensated the process with a while true loop! a mistake on my part, i solved it by adding "await get_tree().process_frame". thank you for the tutorial!

  • @VRNocturne
    @VRNocturne Před 8 měsíci

    Hello!
    I just saw this and was able to implement it into my game.
    However, one question: I notice that my progress number goes to 50% then 0% but everything loads just fine.
    Hiding the number (replacing with just Loading...) makes it look good and still works correctly, but I am curious as to why the progress stopped at 50% and then went to 0% before loading the finished scene?

    • @JumboGamedev
      @JumboGamedev  Před 8 měsíci +1

      Hello!
      I think the behavior of load_threaded_get_status depends on the scene being loaded, so it is hard to exactly know why this may be happening. It is an interesting scenario; my guess is that at some point through the loading process, more dependencies were discovered (or needed to be loaded), and these dependencies were too many & enough to make the amount that was already loaded negligible. You may find these resources helpful, if you want to go into more detail ( github.com/godotengine/godot/blob/4.2/core/io/resource_loader.cpp#L509 ), ( github.com/godotengine/godot/issues/56882#issuecomment-1377612987 )
      Side note: I think this behavior may change depending on the version of Godot or the OS you are using.

    • @VRNocturne
      @VRNocturne Před 8 měsíci

      @@JumboGamedev Thanks for those links, was an interesting read and glad to know I'm not (yet) going crazy.
      After fooling with it some more, I noticed that the progress goes rapidly to 49% - kinda sits there, goes to 50% and then the scene switches successfully. I think the "save sanity" way is for me to just treat 50% as "100%" and then it will look decent to a player while still showing "hey the game isn't frozen".
      Or go with some other effect and drop the number (a sprite animating, etc).
      The adventures of game dev - when things you didn't think would be a quirk show all their quirks :D

    • @JumboGamedev
      @JumboGamedev  Před 7 měsíci

      @@VRNocturne You are very welcome. I agree, I would also stretch/redistribute the first 50% to cover a substantial part of the 100%. You may want to use a non-linear function that will take the progress value, and it will return the stretched value. For instance, you may use a power function. I found that y = x^0.2 (where x is the progress value) gives a decent distribution.
      Indeed, game dev is really interesting!

  • @velixgd9312
    @velixgd9312 Před měsícem

    Why does the error 'Invalid get Index "progress" (in base string)' appear?

    • @JumboGamedev
      @JumboGamedev  Před měsícem

      It seems that you have `progress` as a string and you are trying to get a character that is out of bound. I think you need to make sure that progress is an array and you are accessing the value in index 0.

    • @velixgd9312
      @velixgd9312 Před měsícem

      @@JumboGamedev Thanks

    • @JumboGamedev
      @JumboGamedev  Před měsícem

      @@velixgd9312 You are welcome!

  • @lofinotion
    @lofinotion Před 11 měsíci +1

    nice video! thanks. but...your chatting sound in the video keeps making me check my gogole chat~ aha

    • @JumboGamedev
      @JumboGamedev  Před 11 měsíci

      Thanks for the feedback! I will try to work on the audio more. It would be helpful if you let me know what aspect of the sound needs to be adjusted? does it need to be louder?

    • @felemeria
      @felemeria Před 10 měsíci

      I would use a different sound effect because it sounds just like a chat message. I have that same issue on all of your videos, but I appreciate the content.@@JumboGamedev

  • @lethn2929
    @lethn2929 Před 9 měsíci

    Okay, I'd just thought I'd drop another bit of knowledge I ended up getting from the Godot contributors chat. I was getting some exceptionally nasty errors and scene corruption issues awhile after with error messages like 'circular dependency'. If you are ever getting these errors, check the referenced scene and script, go into the script and change any 'preload' scenes you have to 'load' this should then fix the problem, the way they've gone about it is cancer though so I'm going to see if they can post up either some kind of documentation or update their error to explain this better because it was the first time I'd encountered this and it's terrifying when you first get it.
    Edit: Not doing this can cause huge problems even when you're just in the editor because of the way preloading works it seems even I even found myself having problems even after I removed the loading scripts.

    • @JumboGamedev
      @JumboGamedev  Před 9 měsíci

      Thank you for sharing!

    • @Nazsgull_
      @Nazsgull_ Před 9 měsíci +1

      "Scene file [scene_name] appears to be invalid/corrupt"... This thing has been giving me a headache for a few days, I'll try your fix and see if it works.
      Edit: it works

  • @lethn2929
    @lethn2929 Před 10 měsíci +1

    In case anyone is wondering how to do a progress bar for loading.
    loadingProgressBar.value = floor(progress[0] * 100)