My assumption is that its caused by erroneously attempting to initialize an FRotator variable with the owner’s rotation in a component’s header file (Line 28). Fair enough, but if I try to fix that mistake on VS Code, and I try to load the project up again to compile, it will still crash before I can do anything…
Yes, thank you! It worked.
Now it doesn’t crash anymore.
The below is the corrected code, with the variables init in BeginPlay. This is just the GameDev tut on Udemy.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "OpenDoor.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MYPROJECT_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;
private:
float InitialYaw;
float CurrentYaw = 0.f;
float TargetYaw;
FRotator OpenDoor;
};
#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();
InitialYaw = GetOwner()->GetActorRotation().Yaw;
TargetYaw = GetOwner()->GetActorRotation().Yaw + 90.f;
OpenDoor = {0.f,TargetYaw,0.f};
}
// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
OpenDoor.Yaw = FMath::Lerp(InitialYaw, TargetYaw, 0.02f);
GetOwner()-> SetActorRelativeRotation(OpenDoor);
UE_LOG(LogTemp, Warning, TEXT("%f"), OpenDoor.Yaw);
// ...
}