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.