Check if running in editor in Unreal Engine 5 C++



This will work on all UObject derived classes

if (UWorld* World = GetWorld()) {
    if (World->WorldType == EWorldType::Editor || World->WorldType == EWorldType::EditorPreview) {
        return;
    }
}