Drawing to view at runtime with PDI (FPrimitiveDrawInterface)

I’ve been looking for a good 3 hours now and previously when I wanted to draw to PDI I looked for days and eventually gave up on my concept. I am trying to get a runtime Gizmo working and have looked at the UE4 source code and there’s a render method within FWidget but is being called through 4 methods, each passing a PDI into the method but would prefer to just have the gizmo object render in its own tick.

I have had a look at FDynamicMeshBuilder and FViewElementDrawer but have tried to inherit from these and override a method that passes a FPrimitiveDrawInterface instance but nothing works.

Does anyone have example code laying around they could share of drawing to PDI?

Bump, even if you have a code sample, I would really appreciate it

What is the problem exactly, are you unsure where you can get hold of a PDI?
In what context do you want to draw something?

I want access to PDI within my class. If that’s not possible then I don’t mind having to create a custom component that does have access to PDI.

I was asking what the context is since that affects how you can get hold of a PDI.
But yes, for the general case, you would want to create a custom component deriving from UPrimitiveCompoent, and a custom scene proxy to go with it.

I have some rather old code here you can look at. It probably wouldn’t compile with current engine versions, but the general process is essentially still the same.

So last night I finally got around to trying this out and it worked, however it was not exactly what I wanted: The elements I drew to screen were frustum culled; the moment the origin of the object the FPrimitiveSceneProxy was attached to went out of view the PDI would disappear. The elements drawn also seemed to clip through 3D geometry, my assumption is that I have to set up a material that disables depth testing? Code below:

class FEditorGizmoProxy : public FPrimitiveSceneProxy


	FEditorGizmoProxy(UEditorGizmoDrawer* Component)
		: FPrimitiveSceneProxy(Cast<UPrimitiveComponent>(Component))

	virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView* View) const override
		FPrimitiveViewRelevance Result;
		Result.bDrawRelevance = IsShown(View);
		Result.bShadowRelevance = IsShadowCast(View);
		Result.bDynamicRelevance = true;

		return Result;

	virtual uint32 GetMemoryFootprint(void) const override
		return(sizeof(*this) + GetAllocatedSize());

	virtual bool CanBeOccluded() const override
		return false;

	virtual void GetDynamicMeshElements(const TArray<const FSceneView *>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, class FMeshElementCollector& Collector) const override
		for(int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
			FPrimitiveDrawInterface* PDI = Collector.GetPDI(ViewIndex);

			auto Box = FBox{ GetActorPosition() - FVector(1.f, 1.f, 1.f) * 50.f, GetActorPosition() + FVector(1.f, 1.f, 1.f) * 50.f };
			auto Color = FLinearColor::Blue;
			DrawWireBox(PDI, Box, Color, SDPG_World, 2.f, 0.f, false);
			PDI->DrawLine(FVector(0.f, 0.f, 0.f), FVector(50.f, 0.f, 0.f), FColor::Orange, SDPG_World, 2.f, 0, false);

	virtual void DrawDynamicElements(FPrimitiveDrawInterface* PDI, const FSceneView* View)


I’m getting increasingly frustrated with this, surely someone’s done this successfully before?

I wish to render a simple gizmo to the screen during runtime, in the packaged game.

Did you find a solution to this? I was also wondering if there was any other way of getting the PDI reference apart from making your own component. The EditorViewportClient overrides

as you said. If I try to do the same the Draw function is just NOT called.

I have the same issue, guys, want to render the translate/scale/rotate gizmo like Editor in runtime Game. Is there any solutions and anybody could help on this.