Help crash

I’m currently at the end of my patience with unreal:

I’m currently following a Udemy course in which they don’t show the required includes so we are left to our own devices. I could go with it except every time i add an include i get the error “this declaration has no storage class or type specifier” and if I manage to get around it, (this is my current status) every time i use GetWorld()->GetPlayerController()->GetPawn() to get the player actor i get the error “pointer to incomplete class type is not allowed”. The code i entered seems to be correct, but Unreal Engine still seems to crash.

For clarification purposes:
GetWorld()->GetPlayerController() works;
I could only get the GetPawn() after i installed Visual Assist;
I’m fairly new to C++ and a complete begginer to unreal although i have dabbled in unity.

Code for the GetPawn thing:

void UOpenDoor::BeginPlay()
{
	Super::BeginPlay();

	// ...
	ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
}

Includes:

#include “CoreMinimal.h”
#include “Components/ActorComponent.h”
#include “Engine/TriggerVolume.h”
#include “Engine/World.h”
#include “GameFramework/DefaultPawn.h”
#include “OpenDoor.generated.h”

First what type of object is UOpenDoor from the looks of it it’s an UObject but it probably should be an actor ie. AOpenDoor. If it’s an uobject GetWorld() probably returns a nullptr which cases a crash. Always make sure to check that a pointer is valid before accessing it in c++.

That mistake is obviously a newbie mistake XD, i neglected the nullptr
EDIT: changed some stuff including that but it still crashes

I’m currently trying it out. But how do you fix the include line thingy? By which i mean “this declaration has no storage class or type specifier” which seems to be related to the UClass placement
EDIT: Still doesn’t work, still crashes

.h
#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Engine/TriggerVolume.h"
#include "Engine/World.h"
#include "OpenDoor.generated.h"

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MYPROJECT4_API UOpenDoor : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UOpenDoor();

protected:
	virtual void BeginPlay() override;

	void OpenDoor();

public:	
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

private:
	UPROPERTY(VisibleAnywhere)
		float OpenAngle = 90.f;
		
	UPROPERTY(EditAnywhere)
		ATriggerVolume* PressurePlate;

	UPROPERTY(EditAnywhere)
		AActor* ActorThatOpens; //Pawn inherits Actor
};

Note: I deleted some of the commets because of word count.

.cpp
#include “OpenDoor.h”
#include “GameFramework/PlayerController.h”

// Sets default values for this component's properties
UOpenDoor::UOpenDoor()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


void UOpenDoor::BeginPlay()
{
	Super::BeginPlay();

	// ...
	if (GetWorld()->GetFirstPlayerController()->GetPawn())
		ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
}

void UOpenDoor::OpenDoor()
{
	AActor* Owner = GetOwner();

	FRotator NewRotation = FRotator(0.0f, -60.0f, 0.0f);

	Owner->SetActorRotation(NewRotation);
}


// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (PressurePlate->IsOverlappingActor(ActorThatOpens) == true) {
		OpenDoor();
	}
	// ...
}

it compiles but crashes on play, I’m a little rusty on C/C++ (I need to practice more :p), what do you mean by giving the pawn class a reference to the trigger object? what I’m doing is checking the trigger volume for the presence of the player pawn, so I don’t think I have to mess with the player pawn…

Hey, luckily I had the same problem. You just need to include GameFramwork/PlayerController.h
The last answer from Kalash61 from this thread shows everything you need to include. Would be great to hear if that work out for you! <3

Would it be possible to show your complete code, .cpp and .h, it’s really difficult to tell otherwise <3

Do you mean it compiles, but it crashes when you hit the Play Button? If yes, did you make sure to give your pawn class a reference to trigger object in the world? Also, you don’t need to ask for IsOverlappingActor(ActorThatOpens) == true; you can safely remove the “== is true”.

I’m sorry, I mean your Opendoor class. You have a representation of it in the World, right? Did you make sure when clicking on it to give it a reference to your Collision Box (which is also somewhere in the World)? <3