Hello, I have a C++ class that is inherited from Actor class. Class is called “Chair”
In the Chair.h I’m creating a private variable:
private:
//Pointer to a Player Controller
APlayerController * PlayerController;
Later in the Chair.cpp in the constructor I’m trying to access that pointer.
AChair::AChair()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Set to primary Player Controller
PlayerController = GetWorld()->GetFirstPlayerController();
}
This hard-crashes the editor without so much as error message (the error window appears and says there’s no error information. Furthermore, when trying to open the project again, it again crashes every time I try to load a project at 71%.
The only solution is to edit Chair.cpp file (commenting or removing PlayerController initialization), and then remove “Intermediate” and “Build” folders from the project, allowing the project to rebuild on startup.
If I do not go the private variable route and create and access PlayerController in the “Tick()” function, it works well.
//Pointer to a Player Controller
APlayerController * PlayerController = GetWorld()->GetFirstPlayerController();
It’s just that I’ll need this pointer several times in several functions, so I wanted to declare it as private class variable and retrieve the controller once in the constructor.
I tried to add UPROPERTY() to variable declaration to no effect.
What am I doing wrong? Or is this just a weird bug?