Apologies… I accidentally posted a reply before completing it…
In Unreal, I followed the steps below:
- Select SM_Door.
- Add Component
New C++ Component
Actor Component
Named component to “OpenDoor”
Create Class
It appears to have created OpenDoor.h and OpenDoor.cpp.
// OpenDoor.h
// Copyright Mitch Campbell 2020
#pragma once
#include “CoreMinimal.h”
#include “Components/ActorComponent.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;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};
// OpenDoor.cpp
// Copyright Mitch Campbell 2020
#include “BuildingEscape.h”
#include “OpenDoor.h”
#include “GameFramework/Actor.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();
// Find the Owning Actor
AActor* Owner = GetOwner();
// Create a rotator
FRotator NewRotation = FRotator(0.f, -83.f, 0.f); // floating values are (pitch, yaw, roll) measured in degrees
// Set the door rotation
Owner->SetActorRotation(NewRotation);
}
// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}