How to preload objects (or assets) in memory?

I’m wondering how to preload objects or assets so that they are in memory before they need to be used.

For example, I’m seeing that fonts or audio take a long time to load the first time.

Font:

Audio:

So I think that if I can load in memory these objects before starting the game (While loading screen) the performance will be much better.

I am currently using GameUserSettings to load the audio files and fonts.

	static USoundAttenuation* GetAttenuation()
	{		
		const USoundsSettings* SoundsSettingsPtr = GetDefault<USoundsSettings>();
		if (!IsValid(SoundsSettingsPtr)) return nullptr;		
		return  SoundsSettingsPtr->Attenuation.LoadSynchronous();		
	}

Any way to preload these files into memory before they are needed?
Any example will be greatly appreciated.
Thank you so much!!

You can place assets in a level and they’ll be loaded along with everything else when that level is opened.

You could make a reference to that asset from within some actor such as a character or GameInstance which will then load that asset whenever the actor is loaded.

However the downside with hard references such as those is that the asset is always loaded which can be a waste of memory if its only used a few times especially as your project scales in complexity and you find the memory usage is exceeding your budget.

If you need a sound to be pre-loaded and it only plays once you add it to the level and assign it an initial life span so that it gets deleted and eventually removed entirely with the next garbage collection.

1 Like

Hi @QuicKTricKz

I will try it

Thank you very much for your help