How to know if game is running in either PIE or Standalone mode?

Hi.

I have some code that I only want to execute when the game is running, either in PIE or Standalone mode.




void MyActor::OnConstruction(FTransform transform)
{
    Super::OnConstruction(transform);
    DoSomething();
}

void MyActor::Tick(....)
{
    Super::Tick(...)
    DoSomething();
}

void MyActor::DoSomething()
{
    // .. do something here...
    if (IsPlayingInEditor) { DoSomethingMore }
    else { DoSomethingElse }
}



Obviously this is not the exact code. Is there a global variable or anything I can use to determine if the game is running?

Thanks

2 Likes

Found it - GetWorld().IsGameWorld()

2 Likes

I realize this is late but it may still be useful to others:



if (GetWorld()->WorldType == EWorldType::PIE || GetWorld()->WorldType == EWorldType::Editor)
{
:
}


8 Likes

Isn’t thel bool GIsEdito;r’ variable meant for this?

was exactly what i needed, thanks!