# Deproject Screen Position to World not working

**URL:** <https://forums.unrealengine.com/t/deproject-screen-position-to-world-not-working/459943>\
**Category:** Blueprint\
**Tags:** screen-position, unreal-engine, world-position, question, Blueprint, CPP\
**Created:** [December 27, 2019, 3:24am UTC](https://forums.unrealengine.com/t/deproject-screen-position-to-world-not-working/459943 "2019-12-27T03:24:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vlady\_Veselinov](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vlady_veselinov/32/621446_2.png) [@Vlady\_Veselinov](https://forums.unrealengine.com/u/Vlady_Veselinov)\
**Post date:** [December 27, 2019, 3:24am UTC](https://forums.unrealengine.com/t/deproject-screen-position-to-world-not-working/459943/1 "2019-12-27T03:24:52Z")

</div>

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++:

 ![294469-ue4editor-wppwhp5tuh.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/f/f/fffc5b0eb9cc2718fa745f70e9173630e7a80863.jpeg)

Here’s my Blueprint (had to wait some time for viewport to be ready)

 ![294468-ue4editor-yxigfkm3fw.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/f/7/ef7092c2930e7714441c8a65cb3467a99d03a501.jpeg)

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?

---

<div class="post-metadata">

**Author:** ![JoSf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JoSf](https://forums.unrealengine.com/u/JoSf)\
**Post date:** [December 27, 2019, 2:15pm UTC](https://forums.unrealengine.com/t/deproject-screen-position-to-world-not-working/459943/2 "2019-12-27T14:15:56Z")

</div>

ABreakoutGameModeBase::ABreakoutGameModeBase()  
{  
PlayerControllerClass = ABreakoutController::StaticClass();  
}

---

<div class="post-metadata">

**Author:** ![Vlady\_Veselinov](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vlady_veselinov/32/621446_2.png) [@Vlady\_Veselinov](https://forums.unrealengine.com/u/Vlady_Veselinov)\
**Post date:** [December 27, 2019, 5:10pm UTC](https://forums.unrealengine.com/t/deproject-screen-position-to-world-not-working/459943/3 "2019-12-27T17:10:47Z")

</div>

I’ve already set that up.

---

<div class="post-metadata">

**Author:** ![JoSf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JoSf](https://forums.unrealengine.com/u/JoSf)\
**Post date:** [December 27, 2019, 5:58pm UTC](https://forums.unrealengine.com/t/deproject-screen-position-to-world-not-working/459943/4 "2019-12-27T17:58:36Z")

</div>

Well, for me the C++ code works correctly.

Are you possessing a different pawn or somehow otherwise changing the view, or have you tried to make sure that the changes to the code have been properly applied (by closing the editor, building the project and re-opening the editor)?

---

<div class="post-metadata">

**Author:** ![Vlady\_Veselinov](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vlady_veselinov/32/621446_2.png) [@Vlady\_Veselinov](https://forums.unrealengine.com/u/Vlady_Veselinov)\
**Post date:** [December 27, 2019, 6:16pm UTC](https://forums.unrealengine.com/t/deproject-screen-position-to-world-not-working/459943/5 "2019-12-27T18:16:24Z")

</div>

I have a different pawn that just has a top-down camera and that is set on the “Default Pawn Class” in a game mode blueprint that is derived from the cpp game mode. I wonder if that might cause the problem.
