ProjectWorldToScreen always return true

The ProjectWorldToScreen should transforms the given 3D world-space point into a its 2D screen space coordinate.

But when it’s not possible, it should return a false boolean to the “Return Value”.

In 4.19 (it’s working fine in 4.18), the return value is always true. And it seems that when the result should be false, the returned screen position is the last valid one.

This probably comes from that line of code :

bResult = Player->PostProcessWorldToScreen(WorldPosition, ScreenPosition, bPlayerViewportRelative);

(In the definition of ProjectWorldToScreen in UnrealEngine/Engine/Source/Runtime/Engine/Private/GameplayStatics.cpp)

Because that function is defined that way :

bool APlayerController::PostProcessWorldToScreen(FVector WorldLocation, FVector2D& ScreenLocation, bool bPlayerViewportRelative) const
{
	return true;
}

(In UnrealEngine/Engine/Source/Runtime/Engine/Private/PlayerController.cpp)

So it basically always return true…

That’s cool, I already submited a bug report, but I wanted to know if it was possible to (temporary) calculate that boolean correctly ? I was thinking about getting the camera rotation, but I can’t find how to do that in blueprint…

I was also thinking about using FSceneView::ProjectWorldToScreen instead of UGameplayStatics::ProjectWorldToScreen, but I prefer not to add useless c++ that I will delete when the bugfix is done. (Yeah, I prefer to add useless blueprint macro than useless c++ function :stuck_out_tongue: !)

Hello,

We’ve recently made a switch to a new bug reporting method using a more structured form. Please visit the link below for more details and report the issue using the new Bug Submission Form. Feel free to continue to use this thread for community discussion around the issue.

https://forums.unrealengine.com/unreal-engine/announcements-and-releases/1410408-unreal-engine-bug-submission-form

Thanks

Yes, I know, I already reported it. This post is just to find a workaround before the fix is released.

Hi,

I’m also looking for solution, did you find any?

ProjectWorldToScreen always returns true even if given world location is out of view target. Actually it should return false.
FYI, i used this function in a for-loop so that i can project an array of 3D WorldLocations onto 2D screen. And also output is not accurate, i can see some offset when displaying 2D Croods.

Hey Vinayaka_P ! Yes, I dig into the code source and used the one from a working version to recreate a blueprint function.

bool UGenericBlueprintLibrary::ProjectWorldToScreenCorrected(APlayerController const* Player, const FVector& WorldPosition, FVector2D& ScreenPosition, bool bPlayerViewportRelative)
{
	ULocalPlayer* const LP = Player ? Player->GetLocalPlayer() : nullptr;
	if (LP && LP->ViewportClient)
	{
		// get the projection data
		FSceneViewProjectionData ProjectionData;
		if (LP->GetProjectionData(LP->ViewportClient->Viewport, eSSP_FULL, /*out*/ ProjectionData))
		{
			FMatrix const ViewProjectionMatrix = ProjectionData.ComputeViewProjectionMatrix();
			bool bResult = FSceneView::ProjectWorldToScreen(WorldPosition, ProjectionData.GetConstrainedViewRect(), ViewProjectionMatrix, ScreenPosition);

			if (bPlayerViewportRelative)
			{
				ScreenPosition -= FVector2D(ProjectionData.GetConstrainedViewRect().Min);
			}

			return bResult;
		}
	}

	ScreenPosition = FVector2D::ZeroVector;
	return false;
}

But it’s now fixed, so I removed this and use the original node :wink:

(PS : I’m really sorry for not submitting this to help others before being asked, I hate when people don’t do it, but it’s just that I kinda forget :confused: …)

Thank you Herobrine! Looks great!. I’ll try to embed this in my project.