# Drawing 2D Lines with 3D Occlusion

**URL:** <https://forums.unrealengine.com/t/drawing-2d-lines-with-3d-occlusion/446498>\
**Category:** Rendering\
**Tags:** hud, draw, unreal-engine, Rendering, CPP, question\
**Created:** [April 3, 2019, 2:54am UTC](https://forums.unrealengine.com/t/drawing-2d-lines-with-3d-occlusion/446498 "2019-04-03T02:54:50Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![icroiant](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@icroiant](https://forums.unrealengine.com/u/icroiant)\
**Post date:** [April 4, 2019, 9:58am UTC](https://forums.unrealengine.com/t/drawing-2d-lines-with-3d-occlusion/446498/5 "2019-04-04T09:58:49Z")

</div>

With the help of engine source FSplineComponentVisualizer::DrawVisualization and some forum posts, this is what I end up with:

 ![273258-annotation.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/8/0/98039d05ca46d0a63770ec77217e1cb286be1955.png)

Basically what I did was extending UPrimitiveComponent class and override these two functions:

```
virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
virtual FBoxSphereBounds CalcBounds(const FTransform& LocalToWorld) const override;

```

Define your own component bounds to deal with frustum culling with `CalcBounds`.

Then create another class inheriting from `FPrimitiveSceneProxy` to get hold of a `FPrimitiveDrawInterface` pointer ([refer to this forum post][2]) and draw with

```
PDI->DrawLine(LineStart, LineEnd, Color, SceneDepthPriorityGroup, Thickness);

```

If you want your line occluded by other objects, the `SceneDepthPriorityGroup` has to be `SDPG_World`.

With a thickness of `0.0f` the line is constantly 1 pixel wide; however any value above `0.0f` results in the line thickness becoming depth dependent. If you need a constant thickness and want to be able to control the thickness as well, check out `FSceneView::WorldToScreen`, which returns a `FVector4`, then use the W component of that vector to scale the line thickness.

---

_[View the full topic](https://forums.unrealengine.com/t/drawing-2d-lines-with-3d-occlusion/446498)._
