Hey guys,
I have some global actors in the World that need to be placed, otherwise the game shall not start.
Cause these actors are defined to exist before pressing play, I try to get these via a static function in a UFunctionLibrary at BeginPlay() from other actors.
APaintRoot* UPaintProjectFunctionLibrary::GetPaintRoot()
{
APaintRoot* paintRoot = NULL; //cant make this static! Not Reset when PlayInEditor -> false referenz when starting over
TArray<AActor*> foundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorldRef(), APaintRoot::StaticClass(), foundActors);
//Exit if more than one.
if (foundActors.Num() != 1)
{
OWN_LOG(LogTemp, 5.0f, FColor::Red, "There are %d %s " , foundActors.Num(), " Actor of PaintRoot available. Only 1 allowed. Exiting");
UPaintProjectFunctionLibrary::Quit();
}
if (foundActors.Num() > 0)
{
return (APaintRoot*)foundActors[0];
}
return NULL;
}
Declaring the variable ‘paintRoot’ as static
static APaintRoot* paintRoot = NULL;
I can do this
static APaintRoot* paintRoot = NULL;
if (paintRoot)
{
return paintRoot;
}
As of: Is There a Way to Reset Static Variables Without Re-Compiling? - Programming & Scripting - Unreal Engine Forums static variables are not reset after PlayInEditor, but it would work fine when launching without editor.
The solution would be resetting the variable somehow (BeginPlay(), EndPlay(), …). But the static is within a static function in a UFunctionLibrary, where there is no member variables, no BeginPlay() or what ever (could not access the static variable in a function anyway).
Is there any macro or something that tells me when PlayInEditor is used?
The code is called at about once a second, so it would be nice to just return what was already found.
regards