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!
@@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.
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:
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
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.
@@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.
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!
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?
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.
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!
This is why you spent half your time riding elevators in the original Mass Effect.
@@gamegems7658True, but I assume this is a much better approach with modern SSD's, right?
@@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.
Well paced and detailed Tutorial, great work!
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:
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()
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.
@@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.
There is no example code in no reply, YOU LIED TO ME D:
@@MoogieSRO TH-cam must have deleted the reply. Sorry.
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!
Glad it was helpful!
What a breath of fresh air this is, compared to Unity's subscene loading... Thank you for taking the time to make this!
The whole "scenes versus objects" nonsense in Unity is why I prefer Godot's flattened Node structure, TBH.
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?
As far as I know, the only issues with asynchronous functionality in Godot 4's HTML5 export are audio related. This should work fine!
can u make inventory system ?
That's a pretty broad topic, what kind of inventory system were you thinking of?
@@gamegems7658 a simple 2d platformer inventory u can drag and drop just want to understand it very well. Thanks alot 🥰
very useful thanks alot❤
Glad it was helpful!
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
Yup! Also, Android. A lot of modern-day systems use a thread for UI that needs to be blocked as little as possible.
thank you for the great guide!
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.
Yes, my desktop PC still runs Windows 7.
@@gamegems7658 that is so sick