Just for someone who wants a solved hunk of code here it is: My .cpp:`
#include “GameFramework/Controller.h”
#include “Engine/World.h”
#include “OpenDoor.h”
#include “GameFramework//Actor.h”
#include “BuildingEscape.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;
}
// Called when the game starts
void UOpenDoor::BeginPlay()
{
Super::BeginPlay();
ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
}
void UOpenDoor::OpenDoor()
{
// Find the owning actor
AActor* Owner = GetOwner();
// Create a rotator
FRotator NewRotation = FRotator(0.f, -60.0f, 0.f);
// Set the door rotation
Owner->SetActorRotation(NewRotation);
}
// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// Pool the Trigger Volume
// If the ActorThatOpens is in the volume
if (PressurePlate->IsOverlappingActor(ActorThatOpens))
{
OpenDoor();
}
}`
And my .h:
#pragma once
#include “Components/ActorComponent.h”
#include “CoreMinimal.h”
#include “Engine/TriggerVolume.h”
#include “OpenDoor.generated.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 OpenAngel = 90.0f;
UPROPERTY(EditAnywhere)
ATriggerVolume* PressurePlate;
AActor* ActorThatOpens; // Remember pawn inherits form actor
};
What really got me was not putting () after GetWorld. I don’t know why it put only some parts in those grey boxes. Kudos.