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!

Bumped into this problem, so I tried to search for how the engine does this internally. And here it is:

// Engine/Source/Editor/TurnkeySupport/Private/TurnkeyEditorSupport.cpp
bool FTurnkeyEditorSupport::IsPIERunning()
{
#if WITH_EDITOR
    return GEditor->PlayWorld != NULL;
#else
    return false;
#endif
}

Unfortunately this is private code in module, but copy paste always works (=

P.S. Just realized OP wanted to rule out Standalone mode as well. The code above only checks PIE. But I’ll leave it here anyway, just in case.