Godot 4 Tutorial - Asynchronous Subscene Loading

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ธ.ค. 2024

ความคิดเห็น • 28

  • @ravveni
    @ravveni ปีที่แล้ว +2

    this is so helpful for larger games! been trying to find a good way to achieve God of War's "no loading screens other than the start" type gameplay, and this is a perfect approach to it!

    • @gamegems7658
      @gamegems7658  ปีที่แล้ว +4

      This is why you spent half your time riding elevators in the original Mass Effect.

    • @skylarcanode-rhodes9771
      @skylarcanode-rhodes9771 11 หลายเดือนก่อน

      ​@@gamegems7658True, but I assume this is a much better approach with modern SSD's, right?

    • @gamegems7658
      @gamegems7658  11 หลายเดือนก่อน +1

      @@skylarcanode-rhodes9771It mostly depends on the art style and flow you're trying to achieve. Asynchronous loading gives the user immediate feedback, so you should almost always use it whether you hide the load in an animated cutscene, use a loading bar, or whatever.

  • @BeeNinetwofive
    @BeeNinetwofive 11 หลายเดือนก่อน +1

    Well paced and detailed Tutorial, great work!

  • @americoperez810
    @americoperez810 ปีที่แล้ว +4

    instead of wasting a bunch of CPU cycles checking the status of the thread in the process function for completion then manually retrieving the resource once its done loading, you can create a thread and just use the regular load function inside of it. inside of the threaded function, you can then use call_deferred() to call a function back on the main thread once your threaded function has finished "loading" your resource. I prefer this method because its very similar to the idea of Signals. Like Signals, you don't have to be continuously checking for the status of something. Instead, that something just tells you when its status has changed.
    Check out example code in my reply below:

    • @americoperez810
      @americoperez810 ปีที่แล้ว

      extends Node
      var thread:Thread = Thread.new()
      @onready var sprite_2d:Sprite2D= $"../Sprite2D" as Sprite2D
      @onready var mona_lisa:Sprite2D = $"../mona_lisa" as Sprite2D
      func _ready():
      thread.start(thread_func)

      func thread_func():
      var mona_lisa_texture = load("res://mona.png")
      var i = 0
      var j = 10000

      while i != 30000000: # LONG WHILE LOOP TO SIMULATE LOADING TIME
      i += 1
      if i % j == 0:
      print(i)
      call_deferred("done")
      return mona_lisa_texture

      func _process(delta):
      sprite_2d.position.x += 2

      func done():
      print("All finished, destroying thread objects")
      mona_lisa.texture = thread.wait_to_finish()

    • @gamegems7658
      @gamegems7658  ปีที่แล้ว +4

      The primary advantage to using the ResourceLoader is that it reports how much of the load has completed when queried, which is necessary in order to implement any kind of progress bar. If you don't need that kind of functionality, then yes, there are certainly other ways to handle asynchronous loading in Godot.

    • @americoperez810
      @americoperez810 ปีที่แล้ว

      @@gamegems7658 great point. I was literally just looking into that very specific situation right before you posted your reply. I'm surprised that the ResourceLoader is the only way to get the progress of a load.

    • @MoogieSRO
      @MoogieSRO หลายเดือนก่อน

      There is no example code in no reply, YOU LIED TO ME D:

    • @americoperez810
      @americoperez810 หลายเดือนก่อน

      @@MoogieSRO TH-cam must have deleted the reply. Sorry.

  • @rawvoxel
    @rawvoxel ปีที่แล้ว

    Thanks for this! I'm just starting and haven't tried any of this, so I wasn't even aware this could be a problem. Bits of knowlegde to tuck away for later!

  • @Haavenstadt
    @Haavenstadt 7 หลายเดือนก่อน +2

    What a breath of fresh air this is, compared to Unity's subscene loading... Thank you for taking the time to make this!

    • @gamegems7658
      @gamegems7658  7 หลายเดือนก่อน

      The whole "scenes versus objects" nonsense in Unity is why I prefer Godot's flattened Node structure, TBH.

  • @permanentgrin9356
    @permanentgrin9356 4 หลายเดือนก่อน

    Thank you so much for this. It was exactly what I needed and perfectly explained at a great pace. Immediate subscribe! Do you happen to know if this can be used in HTML5 exports?

    • @gamegems7658
      @gamegems7658  4 หลายเดือนก่อน

      As far as I know, the only issues with asynchronous functionality in Godot 4's HTML5 export are audio related. This should work fine!

  • @xyprohero
    @xyprohero 3 หลายเดือนก่อน

    can u make inventory system ?

    • @gamegems7658
      @gamegems7658  3 หลายเดือนก่อน

      That's a pretty broad topic, what kind of inventory system were you thinking of?

    • @xyprohero
      @xyprohero 3 หลายเดือนก่อน

      @@gamegems7658 a simple 2d platformer inventory u can drag and drop just want to understand it very well. Thanks alot 🥰

  • @xyprohero
    @xyprohero 3 หลายเดือนก่อน

    very useful thanks alot❤

    • @gamegems7658
      @gamegems7658  3 หลายเดือนก่อน

      Glad it was helpful!

  • @hirang1148
    @hirang1148 ปีที่แล้ว

    Oh so it's like java swing where you need to create new thread for doing complex operation so that the GUI does not freeze

    • @gamegems7658
      @gamegems7658  ปีที่แล้ว +1

      Yup! Also, Android. A lot of modern-day systems use a thread for UI that needs to be blocked as little as possible.

  • @Drivinefire
    @Drivinefire ปีที่แล้ว

    thank you for the great guide!

  • @Low_Fidelity_3D
    @Low_Fidelity_3D 5 หลายเดือนก่อน

    Woah thats one of the older versions of windows, isn't it? I can tell because the window borders look like... well, windows. That was back when the UI design for the OS was actually good.

    • @gamegems7658
      @gamegems7658  5 หลายเดือนก่อน +1

      Yes, my desktop PC still runs Windows 7.

    • @Low_Fidelity_3D
      @Low_Fidelity_3D 5 หลายเดือนก่อน

      @@gamegems7658 that is so sick