[PLUGIN] Savior

You have figured everything correctly, but there’s some aspects of Unreal Engine that you are missing;

Classes, member of GameFramework’s Game Mode group, are always dynamically spawned at runtime by Unreal Engine when you hit Play button:

Notice the "_C_0 " suffix on your Player Controller class… once you quit and play again, that will change to "_C_1 ", "_C_2 ", etc…

Your Controller class, if you want it to be a data container in save slots, and restore properties in it from a load process (such as that test actor reference), it is lacking a SGUID for itself, so you should setup one for the Controller:


With a SGUID on PlayerController class, that is resolved.


Now, there’s the complicated part. Multithreading.
When you execute a Save/Load World (Async) operation, you are running multithreaded code. This is complicated.

What can happen (and it is the case here), is that one thread can finish work before something else has finished. I mean, because you are referencing an Actor that must be respawned before inserted into the array, Savior will not sit and wait for Unreal to finish spawning this Actor. Something like this is what is going on in plugin’s “head”:

  • Begin Loading process (Async)
  • Player Controller instance found: load all its data.
  • Decision: Looking for Actor XX, need to respawn.
  • Decision: Set value of ‘TestActor’ reference, instance not found.
  • Skip, continue loading data…

Meanwhile, the Game World is there doing this:

  • Oops somebody requested to spawn this actor, spawning…

Savior’s own thread by this time is:

  • Welp, all things loaded, I’m done, shutting down this thread.

The recently spawned actor:

  • Okay guys, I’m ready! … guys?! Hello?

That’s kindda the reason why you can’t figure out why the TestActor reference can’t find the spawned actor. See logs:

Save

Load

The reference in your PController is loaded way waayy before the actor is done respawing.


How to solve this kind of race condition ?
It’s somewhat simple, you can hijack the “On Finish Respawn” event from the actor itself make it do a polite request to inject itself back into the TestActor reference within the Player Controller instance, for example:

The thing is: threading is a complex thing to deal with some times.
If there’s any doubt, let me know.