How to detect playing in PIE mode in an UObject constructor?

Due to duplication, my UObject is copied and instantiated again as entering PIE.
In the UObject constructor, I use (this)->IsPlayInEditor() but it keeps return false

Do you know inside the constructor of an actor or component, how could we determine whether it is being placed into the level or being instantiated due to duplication in PIE?

I actually tried ()->IsPlayInEditor() but it just returns false.
I also found out about GIsPlayInEditorWorld and GEditor->PlayWorld && (!GEditor->bIsSimulatingInEditor). Are those checks are reliable?


You most likely should not use constructor for whatever you doing, constructor should not contain anything other then defaults and component declarations, you probably should do this in OnConstruction event: AActor::OnConstruction | Unreal Engine Documentation

1 Like

OnConstruction is Actor specific method. TS talked about UObject.

if (GIsEditor && FApp::IsGame())
// …