# Draw a line form widget position to 3d world position on screen

**URL:** <https://forums.unrealengine.com/t/draw-a-line-form-widget-position-to-3d-world-position-on-screen/486449>\
**Category:** UI\
**Tags:** project-world-locati, unreal-engine, UI, Widget, question\
**Created:** [July 20, 2021, 8:39pm UTC](https://forums.unrealengine.com/t/draw-a-line-form-widget-position-to-3d-world-position-on-screen/486449 "2021-07-20T20:39:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrLloyd88](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MrLloyd88](https://forums.unrealengine.com/u/MrLloyd88)\
**Post date:** [July 20, 2021, 8:39pm UTC](https://forums.unrealengine.com/t/draw-a-line-form-widget-position-to-3d-world-position-on-screen/486449/1 "2021-07-20T20:39:14Z")

</div>

trying to draw this line from a widget where the end point follows an actor on screen as the player/camera moves.

I Think ive gotten pretty close by trial and error so far and a lot of research.  
Its updating as the player moves around but its off by quite a bit.

What ive got so far-

```
int32 UCodeEditor::NativePaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const
{
	if (!OwningInteractable)
	{
		UE_LOG(LogTemp, Warning, TEXT("Code Editor has no owning interactable"));
		return LayerId;
	}

	FVector2D InteractableLocation;
	UGameplayStatics::ProjectWorldToScreen(
		GetWorld()->GetFirstPlayerController(),
		OwningInteractable->GetActorLocation(),
		InteractableLocation
	);

	FVector2D ScreenEnd = TextInput->GetCachedGeometry().AbsoluteToLocal(InteractableLocation);

	FPaintContext Context(AllottedGeometry, MyCullingRect, OutDrawElements, LayerId, InWidgetStyle, bParentEnabled);
	FVector2D ScreenStart = TextInput->GetCachedGeometry().GetLocalPositionAtCoordinates(FVector2D(1.f, 0.f));
	UWidgetBlueprintLibrary::DrawLine(Context, ScreenStart, InteractableLocation, FLinearColor::Yellow, true, 2.0f);

	return LayerId;
}
```

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [July 22, 2021, 4:26pm UTC](https://forums.unrealengine.com/t/draw-a-line-form-widget-position-to-3d-world-position-on-screen/486449/2 "2021-07-22T16:26:38Z")

</div>

Hello! But what is the problem? Code seems ok!

---

<div class="post-metadata">

**Author:** ![MrLloyd88](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MrLloyd88](https://forums.unrealengine.com/u/MrLloyd88)\
**Post date:** [July 25, 2021, 7:11pm UTC](https://forums.unrealengine.com/t/draw-a-line-form-widget-position-to-3d-world-position-on-screen/486449/3 "2021-07-25T19:11:35Z")

</div>

Figured it out, i was getting the logic from a blueprint example and the order of roll, yaw and pitch is different in the cpp function. Simple mix up. Thanks anyway!
