Keeps crashing after successfull C++ component build from VS

How are you calling the GetFirstPlayerController( ) function from a UWorld reference?

Can you post the code that you have written that does this?

Thanks.

I’ve been following a course on Udemy.com with videos on how to use Unreal so that is where this code is coming from. However it won’t work once I initialize ActorThatOpens in the openDoor default constructor. I take that part out and it fires up but I can’t open a door unless I eject and set the door to the default pawn created at run time, which is problematic. Note that PressurePlate is the trigger volume in front of the door and is connected to the door being opened. Once there is a overlap of the PressurePlate and the ActorThatOpens (default pawn) the door should open.

openDoor.cpp

UopenDoor::UopenDoor()
{
	PrimaryComponentTick.bCanEverTick = true;
	ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn(); // <---The problem here
	
}


// Called when the game starts
void UopenDoor::BeginPlay()
{
	Super::BeginPlay();
	//	OpenDoor();
	// ...
	
}

void UopenDoor::OpenDoor()
{
	AActor * owner = GetOwner();
	FRotator rotator = FRotator(0.f, -55.f, 0.f);
	owner->SetActorRotation(rotator);
}


void UopenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

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

openDoor.h

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UopenDoor : public UActorComponent
{
	GENERATED_BODY()

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

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

	void OpenDoor();

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

private:
	UPROPERTY(VisibleAnywhere)
		float OpenAngle = 90.0f;
	UPROPERTY(EditAnywhere)
		ATriggerVolume* PressurePlate;
		AActor* ActorThatOpens;
};

I have been having this issue for more than 2 days now. It was working just fine 3 days ago though and now its being all buggy and having issues that make no sense. What I did is access the start content stuff and throw a door and a door frame on the level in the editor. Then I created a c++ component called opendoor which would access the actor and swing open the door with frotator. This all went fine 3 days ago and was working but crashed later on after adding more code building. Today I made a new project and went back to the start again and now it wont even let me make the opendoor component. Right after I built the project in Visual Studio and it went successful the editor crashed showing the error below. Now every time I try to go back into it its the same thing as the project from 3 days ago with the same error log. Don’t understand. This is making me really want to stop getting into Unreal Editor and find a new game engine. Can anyone help?It looks like its saying access violation. What does the error log mean?