✅ Solved: Wait for all assets to load
I’ve brought this up before, but the last answer I got was just to make assets smaller.
My game uses Rive for all objects. I have a callback when loading a rive file so that my game shows a progress bar so it won’t allow the user to play the game until everything is loaded.
This is fine on a quick connection, but some testers have complained about image assets taking a while to populate. I can simulate this in chrome by throttling my connection in Chrome debugging tools.
The closest thing I have seen is Lance’s example here:
However, this assumes that the assets are hosted separately instead of in the Rive file. I know I could have a callback in the loadContents function of the CustomFileassetLoader but I have no idea how many assets I actually need to wait for.
Is there a way to ensure all the file’s assets are loaded before continuing?
Here’s a video of what is happening:
20250628-2231-33.1420159.mp4In this example, the I have a function to load the cutscene:
static async showCutscene(name, callback = null) {
var bytes = await (await fetch('assets/rive/cutscenes/' + name + '.riv')).arrayBuffer();
this.cutscene = await this.rive.load(new Uint8Array(bytes));
this.cutscene.artboard = this.cutscene.artboardByName('Cutscene');
this.cutscene.artboard.volume = Sound.GetSoundVolume() * 0.01;
this.cutscene.stateMachine = new this.rive.StateMachineInstance(
this.cutscene.artboard.stateMachineByName('State'),
this.cutscene.artboard
);
this.cutscene.callback = callback;
this.cutscene.loaded = true;
this.cutscene.renderDelay = 0;
}As you can see, I have an await on the load and I set the bool for loaded to true once it is loaded.
Later I check that loaded is equal to true before rendering but it still shows the rive file before it has loaded all the assets resulting in a pink screen for a few seconds. Is there any way to get the asset count from the file? Maybe I could have the asset loader function count the number of assets that come back before rendering?
I had just added an arbitrary delay before but as I try with slower connections and lots of files, the problem is getting harder to manage and predict.