Dear Epic,
I’m engineering a save system for UE4 where I reload actors from a FString of their class path during runtime.
The issue I am having is that if all instances of a particular BP are destroyed using AActor::Destroy during runtime, after GC runs, then BP class itself seems to get unloaded, and then calls to StaticLoadClass dont work.
However, the odd thing is that if I run my serialization logic a second time, reloading the file in the same tick, then the BP class always gets found on the second try!
So again the flow of events
1 save the level, saving as a string all of the paths to all BP classes of all actors
I use this code:
//Get Path
static FORCEINLINE FString GetClassPath(UClass* ClassPtr)
{
return FStringClassReference(ClassPtr).ToString();
}
template <typename T>
static FORCEINLINE T* LoadClassFromPath(const FString& Path)
{
if(Path == "") return NULL;
return Cast<T>(StaticLoadClass(T::StaticClass(), NULL, *Path, NULL, LOAD_None, NULL));
}
2 All instances of the actor BP are Destroyed out of the level, during runtime.
3 Garbage Collection has a chance to run.
4 When I load the class string paths the first time I get this error:
LogUObjectGlobals:Warning: BlueprintGeneratedClass /Game/PowerUps/RedGem/RedGemBP_Med.RedGemBP_Med_C is not a child class of Class /Script/CoreUObject.Class
This is a message produced by StaticLoadClass.
Then I Run Static Class Again, Same Tick, And It Works!
5 If I then load the file a second time, exactly as before, without waiting even a single tick, then StaticLoadClass finds the BP class just fine!
Do you have any idea why:
1. If **all instances** of the BP class are deleted from the level, during runtime, the BP itself becomes unloaded / StaticLoadClass cannot find it
2. Why is StaticLoadClass saying that the BlueprintGeneratedClass is not a child class of CoreUObject.Class?
3. Why does StaticLoadClass work flawlessly the second time I call it, even in the same tick?
# What Works
Just for clarity, my code works perfectly for actors who are never deleted from the level during runtime, or for actors where at least 1 instance is still in the level.
It's only when ALL actor instances are removed and then GC runs that the BP class cannot be loaded instantly from StaticLoadClass.
#Serialization Not The Issue
I do not think it is an issue with my serialization process because all I do is re-run my load process over again exactly the same way. **I can verify that I am getting the same string path both times that I am then passing along to StaticLoadClass.**
The biggest clue seems to be this odd message:
LogUObjectGlobals:Warning: BlueprintGeneratedClass /Game/PowerUps/RedGem/RedGemBP_Med.RedGemBP_Med_C is not a child class of Class /Script/CoreUObject.Class
#Runtime Commandline Game
Again all of this is in a commandline version of the game, editor is closed.
Thanks!
#♥
Rama