Godot Version
4.2.2
Question
I’ve been fighting this for months now and am completely lost. When using ResourceLoader.load_threaded_request to load scenes loading times are completely inconsistent, spiking randomly.
The inconsistency makes it hard to test. In game with visuals it is worse, reaching 5+ seconds, often after the loading time rises it never goes back down. Taking 5 seconds to load 3mb is outright killing my attempt to stream in my scenes.
I have absolutely no idea where to go form here and any help would be greatly appreciated.
Example code
I have created a simple script to demonstrate. The scenes loading are named t0x0, t1x0, t2x0… and so on up to 6x6. It just loads one after another:
extends Node3D
var path = "res://Terrain/"
var finalPath
var loading = false
var start
var p = 1
var x = 0
var y = 0
# Called when the node enters the scene tree for the first time.
func _ready():
print("Beginning loading time test")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if !loading:
print("starting a load, x: "+str(x)+", y: "+str(y))
start = Time.get_ticks_msec()
finalPath = path+"t"+str(x)+"x"+str(y)+".tscn"
print("path: "+finalPath)
ResourceLoader.load_threaded_request(finalPath,"",false,0)
loading = true
else:
if ResourceLoader.load_threaded_get_status(finalPath) == 3:
var loadingTime = Time.get_ticks_msec() - start
print("loading time: "+str(loadingTime))
loading = false
x+=1
var res = ResourceLoader.load_threaded_get(finalPath)
#trying to make 100% sure it's not cached and get deleted
res.take_over_path(str(p))
res = null
p+=1
if x > 6:
x = 0
y+=1
if y > 6:
x = 0
y = 0
(Scenes consist only of MeshInstance3Ds. No scripts, nothing else. Each scene has an identical amount of data - 3.22mb split over 661 unique .mesh files)
Here is some output:
starting a load, x: 4, y: 2
path: res://Terrain/t4x2.tscn
loading time: 467
starting a load, x: 5, y: 2
path: res://Terrain/t5x2.tscn
loading time: 450
starting a load, x: 6, y: 2
path: res://Terrain/t6x2.tscn
loading time: 2734
All load times where around ~450 until it got to that point, then it went back to ~450 again.
Running a second time we get more inconsistent load times on different scenes:
starting a load, x: 5, y: 0
path: res://Terrain/t5x0.tscn
loading time: 3484
starting a load, x: 6, y: 0
path: res://Terrain/t6x0.tscn
loading time: 2545
starting a load, x: 0, y: 1
path: res://Terrain/t0x1.tscn
loading time: 466
starting a load, x: 1, y: 1
path: res://Terrain/t1x1.tscn
loading time: 465
starting a load, x: 2, y: 1
path: res://Terrain/t2x1.tscn
loading time: 467
starting a load, x: 3, y: 1
path: res://Terrain/t3x1.tscn
loading time: 450
starting a load, x: 4, y: 1
path: res://Terrain/t4x1.tscn
loading time: 483
starting a load, x: 5, y: 1
path: res://Terrain/t5x1.tscn
loading time: 3600
starting a load, x: 6, y: 1
path: res://Terrain/t6x1.tscn
loading time: 2195
What I have tried:
I’ve tried creating my own Thread object and loading normally on that. I’ve made sure nothing is running in the background on my PC that could mess with it. I’ve tried exporting a .exe and running that. I’ve tried moving the .exe to a different HDD, testing both on a mechanical and on my steam library NVME SSD. Tried using subthreads. I’ve also tried saving resources locally to scene since I figured 1 big file is better than 661 small files, but this more than doubles the total size and made loading even slower. I’ve checked task manager and Memory, Disk, and CPU usage are all very low. I’ve tried checking the progress that ResourceLoader offers but it’s just 0,0, 0.5, 0.5, …, 1.0.
One final note: Sometimes I can run this code without a problem for 10 minutes+. When I instance these scenes and add them to my scene (I make sure not to include these operations in the timings) the problem happens within a minute pretty much every time.