Creating a mouse controller cuases UE to crash?

So originally what I did was this:

APlayerController* MyController = GetWorld()->GetFirstPlayerController();

And that didn’t work because it permanently screwed up my project folder.

I just presumed that this was an incorrect way of doing it, so next I tried to follow this tutorial, and it did what it said it would do, which was cool, except I also needed to work with the mouse after, so I created C++ version of the blueprint file they got us to make in the tutorial and it looked like this:

// Fill out your copyright notice in the Description page of Project Settings.

#include "Taank.h"
#include "Mouse_PlayerController_CPP.h"

AMouse_PlayerController_CPP::AMouse_PlayerController_CPP()
{


	bShowMouseCursor = true;
	bEnableClickEvents = true;
	bEnableMouseOverEvents = true;
	
}

And then when I placed the code to try and use it in my pawn cpp file:

AMouse_PlayerController_CPP MouseControll;

(I did have the correct include in the code) and then it did the exact same thing!

I think this is a problem on UE side now, can anyone please help me out here? Thanks

Hey It_-

The tutorial you linked explains setting up the player controller and game mode to use that player controller. You shouldn’t have to add the player controller as a variable to your pawn, rather the pawn will automatically use whatever player controller is set in the GameMode. If you are trying to setup specific controls for a character based on input you can set the input button through the editor and then define what that input does in code by writing the function for the action to be taken and then bind that function in the SetupPlayerInputComponent() function of the pawn/character.

Cheers

Sorry to be blunt, but you haven’t told me anything I don’t know (I’ve already setup keyboard controls perfectly fine), and the problem continues to persist; the problem being that I wanna get my pawn to respond to mouse moments but I have no idea on how to use the mouse in my code without permanently messing up my project.

It may help to know how you’re trying to use the mouse. Are you trying to implement a “click and move” system or have the character constantly follow where the mouse is on screen? I tried following the setup you mentioned by adding a class based on PlayerController with the code you posted in the constructor and then add a class based on Pawn with a pointer to my custom PlayerController class. After compiling I had no issue returning to the editor or closing/reopening the editor. If you’ve reproduced the behavior over multiple projects, could you explain the steps that cause it to occur in a new project with no added content?

Sorry for my late response. I found a way to get it to work, but I’m not sure if it’s elegant or not. The problem I was having was that I wanted to use the DeprojectMousePositionToWorld() function but was unable to set up an APlayerController* variable in the way I described in the first 2 lines of my question. I’m still not entirely sure what the problem was, but my best guess is that the constructor method for my pawn class is executed before the controller file in initilialised, or something like that. Anyway, I solved the problem by instantiating my APlayerController* variable under the BenginPlay() function instead of the constructor. Now I have a new problem of spawning an actor causes UE to crash. So many crashes :confused: Aww well. I’ll figure this one out.