Yes sure. This is what I do in the suggested macro: in the completed path, the macro counts the number of times “completed” have been reached. If it is above the input array size, we know when they have all finished. So I have a blocking operation.
There is a possible caveat though: If someone re-call this macro before all of the latent nodes have completed. Since I use a local variable for the count, I am not sure if macro “compilation” is duplicating the local variable for each call in the graph, or if there is only one local variable for the whole graph. Which could be a problem.
It might work better as a custom event that watches a variable, using a timer. Then calls the next part of the chain.
I agree This is exactly what is doing the cropout sample. But I wanted to do things differently, as I find such “timer + watch variable + continue if ok” to not scale well if it is used everywhere. I mean, this has a tendency to produce spaghetti code.
So as for the Macro itself, well, it is difficult to explain how it works without a video. But let me try.
(Note that I’ve updated the macro with a few bugfixes. I’ll put it as a snippet soon, I just want to be sure it is 100% working first)
The basic idea is that:
First, the “for loop” executes (the first comment box), calling async load class asset on each element. Nothing more is done at this point. On completion of the for loop, the total count is stored in a variable (the comment box just below), and the macro actually exit without anything more.
Then, at a later point in time, the macro is automatically “re-entered” on the Async Load Class Asset, but this time will go through the “Completed” path (the second big comment box). Each time it will decrement the counter. If the counter is above zero, the macro exit without doing anything more. If the counter is below zero, THEN the macro exits on the “Completed” output.
The macro user just have to link this completed output to next operations he wants, that depends on the assets to be really loaded. He will be sure that everything have been correctly loaded.
Anyway, thank you for all your feedback ! You helped me come up with a solution that works for my use case. At least until the dreaded for loop finishes to behave weirdly with latent nodes as suggested by several people
The idea of scale has haunter me: GC can undo all that loading if you are not keeping a reference to the classes. In fact in Cropout you can force GC right after completed and all classes not referenced will be dumped.
Asset Manager protects you from this. So I guess it’s a matter of overall design rather than a solution to a specific problem?
Yeah, this is more for overall design. In the Cropout sample, everything can be screwed up if the GC passes right after loading the assets, as nobody hold a reference to them…
On the macro, I added a “Class” array as output, so that the loaded result can be stored safely and prevent GC doing nasty things