Hi,
I’m new to unreal. I’m following a tutorial and seem to have failed at the first compile attempt.
I’m getting a few errors but I suspect they are all related to the UBoxComponent - undeclared identifier.
It feels like I’ve forgetten to include something as when I’m typing in Visual Studio UBoxComponent never appears as an 'autofill option.
I’ve pasted the code below and would appreciate any help / tips.
I’m using Unreal 4.16.2 on a PC
header file
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include “CoreMinimal.h”
#include “GameFramework/Pawn.h”
#include “RunnerController.generated.h”
UCLASS()
class TUTORIAL_RUNNER_API ARunnerController : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn’s properties
ARunnerController();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UPROPERTY(EditAnywhere)
UShapeComponent* CollisionBox;
UPROPERTY(EditAnywhere)
float Speed = 100.0f;
UPROPERTY(EditAnywhere)
float SwitchSpeed = 300.0f;
void OnSwitch();
void OnRestart();
bool Switched = false;
};
cpp file:
// Fill out your copyright notice in the Description page of Project Settings.
#include “RunnerController.h”
//#include “RunnerSwitcher.h”
// Sets default values
ARunnerController::ARunnerController()
{
// 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;
CollisionBox = CreateDefaultSubobject<
UBoxComponent>(TEXT("Root"));
CollisionBox->bGenerateOverlapEvents = true;
AutoPossessPlayer = EAutoReceiveInput::Player0;
}
// Called when the game starts or when spawned
void ARunnerController::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ARunnerController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FVector NewLocation = GetActorLocation();
NewLocation.Y += Speed * DeltaTime;
NewLocation.Z += SwitchSpeed * DeltaTime * (Switched ? 1 : -1);
if (NewLocation.Z > 70.0f) NewLocation.Z = 70.f;
else if (NewLocation.Z > 420.0f) NewLocation.Z = 420.0f;
SetActorLocation(NewLocation);
}
// Called to bind functionality to input
void ARunnerController::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
InputComponent->BindAction("Switch", IE_Pressed, this, &ARunnerController::OnSwitch);
}
void ARunnerController::OnSwitch()
{
Switched = !Switched;
}