Best way to handle cancelling scene streaming requests?

Godot Version

4.7.1

Question

Best way to handle cancelling scene streaming requests?

I’m building a custom scene streaming system for an open world where a SceneStreaming node asynchronously loads a packed scene when the player enters a load trigger and unloads it when leaving an unload trigger. The load and unload triggers have a margin between them to reduce rapid loading/unloading, but it’s still possible for the player to reverse direction before loading finishes.

The packed scene loaded by a SceneStreaming node can itself contain additional SceneStreaming nodes for streaming smaller regions. In other words, child streaming nodes only exist after their parent scene has been loaded.

From what I can tell, ResourceLoader doesn’t seem to provide a way to cancel an asynchronous resource load once it has started. Is that correct?

If that’s the case, what’s the recommended architecture? Should I let the load finish and simply discard the result if it’s no longer needed? What should i do?

Yeah, no cancel on ResourceLoader threaded loads.

Usual approach is bump a request id when the player leaves, let the load finish, call load_threaded_get(), and only instantiate if the id still matches.

var load_id := 0
func request_load(path: String) -> void:
	load_id += 1
	var id := load_id
	ResourceLoader.load_threaded_request(path)
	# when status is LOADED:
	var res = ResourceLoader.load_threaded_get(path)
	if id != load_id:
		return  # stale, ignore
	add_child(res.instantiate())

Still get it so it doesn’t sit in the loader. Just don’t add it to the tree if it’s no longer wanted.