Hi All,
Is there a way to anchor an actor to the bottom of the viewport? This is so a blocking volume of mine will not offset based on the screen size(AR) of the mobile device being used i.e. (red bars at bottom are the blocking volume)
Initial Viewport size:
Resized:
I have tried to use DeprojectScreenToWorld in both c++ and BP to get an anchor point for the boundary.
In c++:
FVector2D ViewportSize;
if (GEngine && GEngine->GameViewport)
{
GEngine->GameViewport->GetViewportSize(ViewportSize);
}
FVector2D ScreenPosition = FVector2D(ViewportSize.X / 2.f, ViewportSize.Y);
FVector BottomBoundaryWorldPosition;
FVector BottomBoundaryWorldDirection;
bool bScreenToWorld = UGameplayStatics::DeprojectScreenToWorld(UGameplayStatics::GetPlayerController(this, 0),
ScreenPosition,
BottomBoundaryWorldPosition,
BottomBoundaryWorldDirection);
BottomBoundaryWorldPosition.Z = 0.f;
if (bScreenToWorld)
{
BottomBoundary->SetWorldLocation(BottomBoundaryWorldPosition);
}
In BP:
Both of these are only returning the center of the viewport. I feel as though I might not fully understand how the deprojection works. In the picture below the debug circle is the result of the deprojection.
The target texture in the above image is the location in world space I would like to get in order to set the position on the blocking volume. I was able to draw the image in the desired location, but only using EventRecieveDrawHud in the HUD BP.
Am I wrong in the way I’m using DeprojectScreenToWorld, or is this not possible?
If anyone has another approach I could take to achieve anchoring the boundary, I will take any advice I can get. I was thinking of manually placing the boundary for each all (most) screen sizes; recording the location, getting the viewportsize when the game is launched, and runnning a switch statement with each case being the proper location. I would like to avoid this approach if possible. Thanks so much for your time!