#unreal

You can mark components editor only using bIsEditorOnly = true. You also need to wrap the property declaration for the component and any code using it with #if WITH_EDITORONLY_DATA.

The purpose of setting the bool value is a bit unclear. Without WITH_EDITORONLY_DATA, packaging for shipping will fail, so the bool flag seems unnecessary if you need to compile it out anyway.

Editor only components as root component

You should not use editor only components as the root component of an actor. It is possible to do, but if you have other components which attach to the root component, it can cause bugs.

If you really really want to use an editor only component as root, you must replace it with something else for non-editor builds. Otherwise you will get crashes.

#if WITH_EDITORONLY_DATA
Billboard = CreateDefaultSubObject<UBillboardComponent>("Foo");
Billboard->bIsEditorOnly = true;
RootComponent = Billboard;
#else
SceneComponent = CreateDefaultSubobject<USceneComponent>("Scene");
RootComponent = SceneComponent;
#endif