[Request] Draw editor event for blueprints and native

Coming from Unity, one feature they have is an easy way to draw debug lines for custom classes in the editor. Please see OnDrawGizmos and OnDrawGizmosSelected .

Currently there appears to be no easy way to quickly draw debug lines, or information to the editor scene view that is updated every tick, or atleast every time properties of an actor or component updates. Sometimes I have the need to create actors which have no visual representation but need debug lines, arrows, spheres, boxes or a combination of these to show what they do in the world.

Solution:

Create an event that is fired in blueprints that is only happens in the editor. This event could happen every tick and the user could decide from there what to draw using DrawDebugLine() or some other function. This could also be applied to components in C++. Components could have an editor only function that the user could override and draw any necessary data to the world.

1 Like

Whats “DebugLine”?

You can use HUD canvas to draw things, some components can be helpful too like Shape Components which you can make them visible during game play if you want

Consider that you something like a Route which references 2 notes in the scene for positions. The route uses the order of these notes to determine which is the start and end point. A nice thing to be able to do would be to draw an arrow from the first note to the second. Right now there is no good way to do this. Unity makes this very easy by overriding OnDrawGizmos() where you can then just draw an arrow from the first point to the second and any other data you wish to display in the editor only.

I think you think too much Unity way :stuck_out_tongue: From what you saying it sounds like you want draw a line from Point A to Point B, it does not need to be done same way as in Unity, not to mention what you want sounds impossible in UE4 as you can’t draw things per frame, you can only do there with HUD canvas, you need to use components instead. As long it result is what you desired it’s ok right?

Maybe try USplineComponent, as i know you can use it to draw lines in 3D

Well it certainly is possible to draw things per frame in UE4, see DrawDebugLine, DrawDebugSphere, etc, all those have the ability to clear each frame.

Right now whats not possible is to draw things only in the editor while not playing. Unity may not be as advanced in some areas as UE4, but it is lightyears ahead in editor customization and usability, and this is one of the areas where it is simply easier to use and better thought out than UE4 right now.

I did some digging into the editor and found ComponentVisualizers in the editor code. These have the basic idea of what I am looking for where you can draw the anything necessary to visualize the component to the editor SceneView, however there are only a handful of components which take advantage of this, and they are hardcoded into the editor, which is not ideal at all.

You can do this. What you want to look into is the FComponentVisualizers. It is not as straightforward as the unity OnDrawGizmos but it is more powerfull .

This does require you to have a custom component in your BP in order to get it to work, but that could be as easy as creating an empty component called “FMyDummyDebugComponent” or whatever you want. You then create something like this :

class FMyDummyDebugVisualizer : public FComponentVisualizer
{
public:
	virtual void DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI) override;
}

in DrawVisualization you can do pretty much anything you want. Look into current implementations in the engine code for examples. You have lots of “DrawOrientedWireBox”, “DrawWireCone” type functions to play around with.

The following code will register your visualizer to be called whenever a UMyDummyDebugComponent is selected in the editor :

GUnrealEd->RegisterComponentVisualizer(UMyDummyDebugComponent::StaticClass()->GetFName(), MakeShareable(new FMyDummyDebugVisualizer ));

However there is a trick to it. GUnrealEd will be null at startup unless you set your gameplay module to load after the engine. Do this by setting “LoadingPhase”: “PostEngineInit” in the uproject file. Once you have done this you can register at module Startup.

I do this by overloading the FDefaultGameModuleImpl and registering in virtual void StartupModule() override.

Here is an example of my visualizer for our tile definition component. When any blueprint contains components of this type it renders shields where you have setup the properties to have covers. This works well in both blueprint editor and in scene view.

Cheers,

I remember looking through this at one point. This is definitely useful for C++, which I work in most of the time, however this really doesn’t give non-programmers or blueprint focused programmers the ability to do things on the fly. It would be nice if there was a way for people who want to keep most of their work in blueprint, to be able to draw visualization directly in the blueprint graph.

Yeah. That would be pretty useful. Just wanted to show that it is not necessary to edit any engine code to write your own.

I got it working. A couple extra tricks were necessary:

  1. In my project’s (projectname).Build.cs file, I had to add “UnrealEd” as a dependency. Otherwise, use of FComponentVisualizer would cause a linker error.

  2. I had to add a ADebugEnabledActor class that extends from AActor. All it has is a virtual DebugDraw function. My route data actor extends from ADebugEnabledActor instead of AActor so that my FDebugVisualizer ( which is registered to my UDebugVisualizerComponent ) can cast its owner to ADebugEnabledActor in DrawVisualization (otherwise the cast will fail) and call its DebugDraw function. Much more complicated than I was hoping, but it works! (if there is a way to simplify any of this, or do away with the extra inheritance please let me know)

  3. You can add something like this to automatically add the debug visualization plugin to your actors (might want to make it editor only or this extra data will end up in your shipped code. or do it later):

UDebugVisualizerComponent* DebugVisualizerComponent = ObjectInitializer.CreateDefaultSubobject(this, TEXT(“DebugVisualizer”));

To bump this,does anyone know if there’s a way to show the visualizers when the actor is NOT selected?

After reading up on this I get the idea that it will only display visualizations when the component is selected, is this true? Or is there a way to draw visualizations that will show at all times in the editor?

What about blueprint? I never use C++ and I cant use it, how can I make some widget for my components that visualize some property in scene? specially when I add component on actor because in that case many simple feature like show gizmo to Vector3 not work.