Hi y’all, I’m trying to draw a debug square in the top-left corner of my screen. De-projecting screen to world works in blueprint but not in c++. Why is that?
Pink is BP, red is C++:
Here’s my Blueprint (had to wait some time for viewport to be ready)
And here is the equivalent C++:
void ABreakoutGameModeBase::BeginPlay()
{
Super::BeginPlay();
UWorld *World = GetWorld();
Controller = Cast<ABreakoutController>(World->GetFirstPlayerController());
World->GetTimerManager().SetTimer(CheckViewportHandle, this, &ABreakoutGameModeBase::TrySpawnBlocks, 0.1f, false, 0.2f);
}
void ABreakoutGameModeBase::TrySpawnBlocks()
{
UWorld *World = GetWorld();
FVector OutSpawnPosition, OutSpawnDirection;
Controller->DeprojectScreenPositionToWorld(0, 0, OutSpawnPosition, OutSpawnDirection);
DrawDebugPoint(World, OutSpawnPosition, 100.f, FColor::Red, false, 10.f);
}
I’m just trying to spawn some actors relative to where the camera is looking. What am I doing wrong here?