Question on Asynchronous Asset Loading and using GameInstance as loading manager

Hi, i was hoping someone could help me clarify a few concepts.
My Goal is to prototype a system that can handle a scalable amount of assets, Asynchronous loading seems to be the way to go.
but I am still a but confused as to how TSoftObjectPtr works with memory allocation.

I read through the
Asynchronous Asset Loading docs,
and was using the following as reference.

TUTORIAL C++ - Runtime Async Load Modular Character

In my current case, I have a Character class, that is statically loading a custom UAssetData class in the constructor, in this UAssetData I have defined all the parts a character needs with TSoftObjectPtr<USkeletalMesh> properties.
similar to the reference forum post.(which has some outdated info).
the Character then requests the asynchronous loading of required assets.

My concern is that when a second character is spawned, that uses the same meshes, they should already be in memory right?.
What happens when the second character calls asynchronous loading on those meshes in memory?
Since they have two instances of a TSoftObjectPtr.

And wouldn’t it be functional to use custom GameInstance class, to hold those TSoftObjectPtr?

Idea being any actor could get the GameInstance and then check if those TSoftObjectPtr hold a loaded object, if not load it. or maybe do some more complex asset management.

I don’t post code because I have yet to flesh it out. and was hoping on some input from anyone, i’ll will be willing to post it for anyone interested if it turns out to be a correct way to handle things.

Cheers community!
Work on your dreams, don’t dream of your work (unless you love your work). :slight_smile:

What happens when async load is called again on the same TSoftObjectPtr?
Async load first checks if the object is loaded in memory before trying to load it. So it will exist in memory only once. You do not need to check if the object is already loaded, the soft pointer takes care of that for you, read below.

Should you use Game Instance to hold TSoftObjectPtrs?
You could, but its not a necesity. Any actor can hold a TSoftObjectPtr since it is basically a string that points to the asset. It does not matter how many Soft Pointers you have and where, even if pointing to the same object, said object will be loaded only once, irregardles of which actor is requesting it to be loaded.

As long as there is a single HARD reference to an object it will remain loaded. So if you Async Load a soft object pointer but you do not reference with a regular pointer somewhere it will get garbage collected. TSoftObjectPtrs will not prevent garbage collection, so keeping an array of these anywhere will not keep objects loaded. Instead, every time you load an object be sure to reference it as a regular pointer or you will lose it (which might be a good thing actually! if you are not using it you certainly do not need it).

Please do not forget to mark this answer as the correct one if it is what you where looking for so others having the same doubt can easily find it.

Hope this info helps you. Make it a great day!

Thanks Bariudol! it does help! and for anyone that stumbles upon this post, here is a few pointers on the reference forum post i was using above.

TAssetPtr is still not deprecated, but it will be, and should be replaced with TSoftObjectPtr.

and TArray<FStringAssetReference> ObjToLoad; should be TArray<FSoftObjectPath> ObjToLoad;

and ToStringReference() should now be ToSoftObjectPath()

semi unrelated but TSubobjectPtr is also deprecated, and you should use regular component pointers instead.