Hello.
I recently started C++ in UE.
I created class DefaultPlayer. I added few components and a simple movement. When I compiled this class UE crashed. Now it crashes every time I enter this project, making it unusable.
Here’s my DefaultPlayer.h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Pawn.h"
#include "DefaultPlayer.generated.h"
UCLASS()
class UNREALISAAC_API ADefaultPlayer : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
ADefaultPlayer();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
// Movement
FVector2D MovementInput;
FVector2D RotationInput;
void MoveForward(float AxisValue);
void MoveRight(float AxisValue);
// Components
UPROPERTY(EditAnywhere)
UShapeComponent* PlayerCollision;
UCameraComponent* PlayerCamera;
};
And DefaultPlayer.cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#include "UnrealIsaac.h"
#include "DefaultPlayer.h"
// Sets default values
ADefaultPlayer::ADefaultPlayer()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
PlayerCollision->CreateDefaultSubobject<UCapsuleComponent>(TEXT("PlayerCollision"));
RootComponent = PlayerCollision;
PlayerCamera->CreateDefaultSubobject<UCameraComponent>(TEXT("PlayerCamera"));
PlayerCamera->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f));
PlayerCamera->bUsePawnControlRotation = true;
}
// Called when the game starts or when spawned
void ADefaultPlayer::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ADefaultPlayer::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
MovementInput = MovementInput.GetSafeNormal() * 500.0f;
FVector NewLocation = GetActorLocation();
NewLocation += GetActorForwardVector() * MovementInput.X * DeltaTime;
NewLocation += GetActorRightVector() * MovementInput.Y * DeltaTime;
SetActorLocation(NewLocation);
}
// Called to bind functionality to input
void ADefaultPlayer::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
InputComponent->BindAxis("W-S", this, &ADefaultPlayer::MoveForward);
InputComponent->BindAxis("A-D", this, &ADefaultPlayer::MoveRight);
}
// Movement
void ADefaultPlayer::MoveForward(float AxisValue)
{
MovementInput.X = FMath::Clamp<float>(AxisValue, -1.0f, 1.0f);
}
void ADefaultPlayer::MoveRight(float AxisValue)
{
MovementInput.Y = FMath::Clamp<float>(AxisValue, -1.0f, 1.0f);
}
It’s 3rd project I’ve lost because of this. What am I doing wrong?
Please help me.