A lot of other engines have simple functionality to do this built in (as it is extremely useful for debugging), but I haven’t been able to find an easy way to do it in UE4.
All I really want to do is draw the index of my route data’s nodes at the node position in 3D when the route is selected in the editor. (in both edit and play mode)
I was using a trick posted in the following thread, and managed to create a component that can draw debug primitives while in edit mode.
However, the only arguments I have in this function are (const FSceneView* View, FPrimitiveDrawInterface* PDI). If I can get a Canvas, it looks like I can at least call DrawText, but trying the following was just making the editor crash somewhere deep in DrawText.
static const FName CanvasName(TEXT("CanvasObject"));
UCanvas* Canvas = (UCanvas*)StaticFindObjectFast(UCanvas::StaticClass(), GetTransientPackage(), CanvasName);
if (Canvas)
{
Canvas->SetDrawColor(255, 255, 255);
UFont* RenderFont = GEngine->GetSmallFont();
const FVector ScreenLocation = Canvas->Project(pos);
Canvas->DrawText(RenderFont, FString::Printf(TEXT("%d"), i), ScreenLocation.X, ScreenLocation.Y);
}
I also tried (experimentally) creating a canvas if it doesn’t exist like certain parts of the engine are doing, but it crashed in the same place.
Is there a correct way to get the current canvas somehow, or a better way to draw debug text on the screen?
Also, if any Epic devs are reading this: Please implement easy debug primitive and 2d/3d text printing functions that can be called from anywhere. A huge number of people would benefit from this.