# Project World to Screen Location stops returning a value

**URL:** <https://forums.unrealengine.com/t/project-world-to-screen-location-stops-returning-a-value/57135>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [March 3, 2016, 1:19pm UTC](https://forums.unrealengine.com/t/project-world-to-screen-location-stops-returning-a-value/57135 "2016-03-03T13:19:10Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![BrandenMarais](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BrandenMarais](https://forums.unrealengine.com/u/BrandenMarais)\
**Post date:** [January 3, 2024, 7:52am UTC](https://forums.unrealengine.com/t/project-world-to-screen-location-stops-returning-a-value/57135/11 "2024-01-03T07:52:50Z")

</div>

Just an update for anyone not getting this to work in UE5.

Code for the .h

```auto
UFUNCTION(BlueprintPure, Category = "UI Math")
static bool ProjectWorldToScreenBidirectional(APlayerController const* Player, const FVector& WorldPosition, FVector2D& ScreenPosition, bool& bTargetBehindCamera, bool bPlayerViewportRelative = false);

```

Code for the .cpp

```auto
bool UIBlueprintFunctionLibrary::ProjectWorldToScreenBidirectional(APlayerController const* Player, const FVector& WorldPosition, FVector2D& ScreenPosition, bool& bTargetBehindCamera, bool bPlayerViewportRelative)
{
	FVector Projected;
	bool bSuccess = false;

	ULocalPlayer* const LP = Player ? Player->GetLocalPlayer() : nullptr;
	if (LP && LP->ViewportClient)
	{
		// get the projection data
		FSceneViewProjectionData ProjectionData;
		if (LP->GetProjectionData(LP->ViewportClient->Viewport, /*out*/ ProjectionData))
		{
			const FMatrix ViewProjectionMatrix = ProjectionData.ComputeViewProjectionMatrix();
			const FIntRect ViewRectangle = ProjectionData.GetConstrainedViewRect();

			FPlane Result = ViewProjectionMatrix.TransformFVector4(FVector4(WorldPosition, 1.f));
			if (Result.W < 0.f) { bTargetBehindCamera = true; } else { bTargetBehindCamera = false; }
			if (Result.W == 0.f) { Result.W = 1.f; } // Prevent Divide By Zero

			const float RHW = 1.f / FMath::Abs(Result.W);
			Projected = FVector(Result.X, Result.Y, Result.Z) * RHW;

			// Normalize to 0..1 UI Space
			const float NormX = (Projected.X / 2.f) + 0.5f;
			const float NormY = 1.f - (Projected.Y / 2.f) - 0.5f;

			Projected.X = (float)ViewRectangle.Min.X + (NormX * (float)ViewRectangle.Width());
			Projected.Y = (float)ViewRectangle.Min.Y + (NormY * (float)ViewRectangle.Height());

			bSuccess = true;
			ScreenPosition = FVector2D(Projected.X, Projected.Y);

			if (bPlayerViewportRelative)
			{
				ScreenPosition -= FVector2D(ProjectionData.GetConstrainedViewRect().Min);
			}
		}
		else
		{
			ScreenPosition = FVector2D(1234, 5678);
		}
	}

	return bSuccess;
}

```

Changed:

```auto
if (LP->GetProjectionData(LP->ViewportClient->Viewport, eSSP_FULL, /*out*/ ProjectionData))

```

**To**

```auto
if (LP->GetProjectionData(LP->ViewportClient->Viewport, /*out*/ ProjectionData))

```

And added Daniel\_Alves\_br’s suggestion.

> I suggest you to add na ELSE parameter to set bTargetBehindCamera back to false when look to the tag point again.
> 
> ```auto
> if (Result.W < 0.f) { bTargetBehindCamera = true; } else {bTargetBehindCamera = false;}
> 
> ```

---

_[View the full topic](https://forums.unrealengine.com/t/project-world-to-screen-location-stops-returning-a-value/57135)._
