Crash by playing in GameMode with PlayerController (C++)

Hey Guys, my problem is…
… when I whould like to play my game, my editor crashs. I have an standard GameMode, but with a custom PlayerController. Compiling works.

My Code for the PlayerController:
My Crashreport:

Can anybody help me?

If you have BSP on your level, then the cause may be in 28 and 29 line of code of your PlayerControll.cpp file.

In line 28 you assume, that whenever you hit anything, it’s already an actor, which is wrong. BSP for example isn’t a an actor (thus hit.GetActor() returns nullptr), yet it could be detected by your linetrace. I’m not sure if there are any other objects like BSP that would block linetrace despite the fact they aren’t actual actors.

Anyway, to fix this you could replace your condition in 28th line to this:

if (PC_World->LineTraceSingleByChannel(*hit, cm->GetCameraLocation(), *c_loc + *c_dir * 1000, ECC_Pawn) && hit.GetActor())

Sorry but then the same

What is a parent class of your APlayerControll class?
I’m assuming it’s APlayerController?

If so, your cm variable is null, and you’re assuming it’s not (line 28 again: cm->GetCameraLocation()).

In line 14, you’re trying to cast APlayerController to APlayerCameraManager which is a no-go.
Change that line to:

cm = PlayerCameraManager;

Or you can simply use PlayerCameraManager instead of cm variable.

Also, not something that important, but in line 11, you don’t have to cast ‘this’ to AActor since APlayerController is deriving from AActor class. You can simply make it

PC_Actor = this;

cm = PlayerCameraManager;

Sorry but then I have an compilling error

PC_Actor = this;
I have no compiling error but an crash with

It’s an additional thing i’ve seen in your code. Casting APlayerController to AActor shouldn’t cause any problems, but it’s simply redundant, that’s all.

What error?

Also, could you show updated .cpp file?

So, that was crazy… jet I have no error rather an crash:

an my .cpp file:

Hmm… Weird. Didn’t notice that earlier.

I just tested it and it seems that the issue is with where you’re getting your references to world and camera manager. You do that in constructor, while these objects doesn’t exist yet.

Moving these:

PC_World = PC_Actor->GetWorld(); 
cm = PlayerCameraManager;

To - for example - BeginPlay should solve the issue.

Thank you!

Read comments in answer before

I have one question, when i play it, my player camera manager moves to the left, why?
my code:

This code doesn’t look like it can cause such thing. Could you try to comment out your 32nd line and see if it keeps happening?

When i do that, with the 35nd Line, then nothing happends.

Ok i have add in the 31nd Line