I am trying to replace hard references with soft references for in-game information exchange.
However, inconsistent results of Async Load Asset loading made everything a mess.
It’s actually more complicated but rough explanation of the process is, Press the button, send soft references to UI and SaveGame and Model Spawner, Load and Cast if the destination uses a hard reference. SaveGame uses soft references, the UI and spawners use hard references.
It worked fine when I was running everything with hard references.
However, after replacing soft reference, assets may not load completely, result in inaccurate UI display and models not spawning.
It may take a couple of reloads to get it to work as intended, but it’s pointless if it doesn’t work correctly the first time.
Can someone help me?
Async loading node has two outputs, upper one continues/leaves node in same frame that it was called (before asset is ready), bottom one continues when the asset finished loading. Make sure you don’t try to use the asset before it finished loading and that’s pretty much it. Don’t rely on delay nodes with this approach as loading times can vary.
I always use the bottom output and never use a Delay.
Apparently there’s something wrong with your code, when you say that after couple of reloads it’s working as intended it only means that all the assets are finally in memory so the ‘async load’ completion is instant. My guess is that you are using casts somewhere in code that expect variables to be set but they aren’t yet, due to assets loading.
For example ui widget is async loading icons before creating compass widget and you try to access compass widget from player pawn’s begin play, without actually waiting for it being created.
you also cant call the AsyncLoad Node before its finished, for instance on a for loop
So you can use the upper-path to just-keep doing work that can progress w/o waiting on the load and then, say, flag a bool, or trigger another dependent process once loading is complete (via the bottom path)?
exactly
Ok, looks like I need to rethink the whole process.
I thought that using soft references would just require adding a few steps to hard references, but apparently not.
Thanks everyone for your help.
depending on where it is in your game you can use LoadAssetBlocking, this can cause hitches in your game but is useful for testing
I’ve tried several times but it still doesn’t work.
Obviously the Completed output is being executed without completing the load.
This is the macro I’m using.
After confirming that the load is complete, execute the next load.
This macro is used in one place only and is called only once.
Although this is wired directly to SpawnActor, there is a low probability that all actors spawned in the array.
From what I can see there are several fail scenarios there.
Try to make it as an event, debug step by step and when it’s working convert it to macro (if you really need it) and check if it’s still working. Macros can be difficult to debug.
Maybe this is the problem I’m facing…
That macro was created to accommodate multiple key types.
I tried running the same thing in an event, but the result was the same.
I knew that async loading and loops are a bad combination. And maybe that’s the problem.
This is too difficult for me. I thought I understood it, but something is missing.
I would like to know how others have solved this problem, but apparently no one else is facing the problem except me.
what you do is have an array of pending assets, and you only load the next item when the first is completed.
the possible difference with your marco is what if the macro is called twice? it’ll break the previous load order.
so whenever the event is called to load something it just adds to the pending array
if you need to return a loaded object you can bind to an event
what you can do instead of using for loop is have an array with items to load
async load last item from array
when it’s completed, remove last array item
go from the start until array has zero items
why last item? maybe memory for whole array doesn’t have to be relocated when doing that, like in c++ but it’s only my assumption. you can as well work on first item instead and it will be the same.