How to use FDebugRenderSceneProxy

Hi,

I have a component UMyComponent (derived from UPrimitiveComponent) and want to draw some debug info. For that I have overwritten the CreateSceneProxy function and create a FDebugRenderSceneProxy. See code below. But its not rendering anything.

FPrimitiveSceneProxy* UMyComponent::CreateSceneProxy()
{
	auto proxy = new FDebugRenderSceneProxy(this);
	proxy->DrawType = FDebugRenderSceneProxy::SolidAndWireMeshes;
	proxy->ViewFlagName = TEXT("OnScreenDebug");
	proxy->ViewFlagIndex = uint32(FEngineShowFlags::FindIndexByName(*proxy->ViewFlagName));

	FDebugRenderSceneProxy::FDebugLine dbgLine(FVector(0.f, 0.f, 0.f), FVector(0.0f, 0.0f, 10000.f), FColor::Orange, 160.f);
	proxy->Lines.Add(dbgLine);
	proxy->Boxes.Add(FDebugRenderSceneProxy::FDebugBox(FBox(FVector(-1000.f, -1000.f, -1000.f), FVector(1000.f, 1000.f, 1000.f)), FColor::Green, FTransform::Identity));

	return proxy;
}

“OnScreenDebug” show flag is enabled in the editor.

What do I do wrong or what do I missed?

Thanks,
Takatu

Its now a while and I still need it and I still don’t know how.

for anyone else who arrives here looking for the solution, I figured it out.

a couple more things need to be setup.

override ShouldRecreateProxyOnUpdateTransform to return true.
override CalcBounds to return whatever bounds makes sense for your component.

and finally, you need to extend FDebugRenderSceneProxy to override the GetViewRelevance method like so.

class FCustomDebugRenderSceneProxy : public FDebugRenderSceneProxy
{
	
public:
	
	FCustomDebugRenderSceneProxy(const UPrimitiveComponent* InComponent)
		: FDebugRenderSceneProxy(InComponent)
	{
	}
	
	virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView* View) const override
	{
		FPrimitiveViewRelevance Result;
		Result.bDrawRelevance = IsShown(View);
		Result.bDynamicRelevance = true;
		Result.bShadowRelevance = false;
		Result.bEditorPrimitiveRelevance = UseEditorCompositing(View);
		return Result;
	}
};

also, SetIsVisualizationComponent isnt needed if the component is meant to be more then just a visualization, I found it pointless because I’m just using this to visualize a component that has an actual impact on gameplay. This is set in a lot of other examples, so I’m just making a note of it here.

For anyone else that comes across this, check out this nice blog by some guy named “Steve” :smile:

For anyone else that finds this, a quick summary:
FDebugRenderSceneProxy is useful for rendering debug lines, cylinders, circles, etc in the editor, without needing to click the “play button”
I’ve made use of this to show the bounds of a simulated object or constraint (like a spring on a car) while configuring it in the details panel.
You can render debug lines in the viewport of a blueprint or in the main gameplay viewport.