Some Actors and Components have no visual representation, making them difficult to select, or have important properties that are not visible. Developers can add extra Components to display information while working in the Editor, but these extra Components are not needed during Play In Editor, or when running a packaged build. To address this, the Editor supports the concept of Visualization Components, which are ordinary Components that exist only when working in the Editor.
To make a Visualization Component, create any regular Component and call
SetIsVisualizationComponent on it. Since the Component does not need to exist outside of the Editor, all references to it should be inside of preprocessor checks against
WITH_EDITOR. This will ensure that packaged builds are unaffected by these Components and are guaranteed not to reference them anywhere in code. As an example, the Camera Component uses several other Components to display helpful information in the Editor, including a Draw Frustum Component to show its view frustum. In the header file, the Draw Frustum Component is defined within the class as follows:
// The frustum component used to show visually where the camera field of view is
class UDrawFrustumComponent* DrawFrustum;
Similarly, all references to this this Component will be inside of preprocessor checks against
WITH_EDITORONLY_DATA in the source file. This code, inside of a
WITH_EDITORONLY_DATA check within
OnRegister, checks to see if the Camera Component is attached to a valid Actor, and then adds the Draw Frustum Component code:
if (AActor* MyOwner = GetOwner())
if (DrawFrustum == nullptr)
DrawFrustum = NewObject<UDrawFrustumComponent>(MyOwner, NAME_None, RF_Transactional | RF_TextExportTransient);
// ... Additional code (to run in all builds) goes here ...
DrawFrustum now exists only in the Editor and is considered a Visualization Component, meaning that it won't appear during in-Editor playtesting.