Lesson 83 - Introducing Input Binding

I’ve done something wrong and I’m not sure. I tried this lesson and get a plethora of errors. Attached is my code for the Grabber.h and cpp files

I’m not even sure where I messed up, but I’m hopeful someone will help me.

// Fill out your copyright notice in the Description page of Project Settings.

#include “BuildingEscape.h”
#include “Grabber.h”

#define OUT

// Sets default values for this component’s properties
UGrabber::UGrabber()
{
// 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.
bWantsBeginPlay = true;
PrimaryComponentTick.bCanEverTick = true;
}

/// Called when the game starts
void UGrabber::BeginPlay()
{
Super::BeginPlay();

UE_LOG(LogTemp, Warning, TEXT("Grabber reporting for duty!"));

//look for attached physics handle
PhysicsHandle = GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();
if (PhysicsHandle)
{
	//is found
}
else
{
	UE_LOG(Log_Temp, Error, TEXT("%s missing physics handle component"), *GetOwner()->GetName())
}


//look for attached input component (only appears at runtime)
InputComponent = GetOwner()->FindComponentByClass<UInputComponent>();
if (InputComponent)
{
	UE_LOG(LogTemp, Warning, TEXT("Input component found"))

		InputComponent->BindAction("Grab", IE_Pressed, this, &UGrabber::Grab);
}
else
{
	UE_LOG(Log_Temp, Error, TEXT("%s missing input component"), *GetOwner()->GetName())
}

}

void UGrabber::Grab()
{
	UE_LOG(LogTemp, Warning, TEXT("Grab pressed"))
}

}

/// Called every frame
void UGrabber::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
{
Super::TickComponent( DeltaTime, TickType, ThisTickFunction );

/// Get player view point
FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;

GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(	OUT PlayerViewPointLocation, OUT PlayerViewPointRotation);

FVector LineTraceEnd = PlayerViewPointLocation + (PlayerViewPointRotation.Vector() * Reach);

DrawDebugLine(
	GetWorld(),
	PlayerViewPointLocation,
	LineTraceEnd,
	FColor(255, 0, 0),
	false,
	0.f,
	0.f,
	10.f
);

///set up query paramaters
FCollisionQueryParams TraceParameters(FName(TEXT(" ")), false, GetOwner());

///ray-cast out to reach distance (Private variable to store reach)
FHitResult Hit;
GetWorld()->LineTraceSingleByObjectType(
	OUT Hit,
	PlayerViewPointLocation,
	LineTraceEnd,
	FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
	TraceParameters
);

///GetHit
AActor* ActorHit = Hit.GetActor();
if (ActorHit)
{
	UE_LOG(LogTemp, Warning, TEXT("Line Trace Hit: %s"), *(ActorHit->GetName()))
}

}

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “Components/ActorComponent.h”
#include “Grabber.generated.h”

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UGrabber : public UActorComponent
{
GENERATED_BODY()

public:
// Sets default values for this component’s properties
UGrabber();

// Called when the game starts
virtual void BeginPlay() override;

// Called every frame
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;

private:

//Reaching Range For Player
float Reach = 100.f;

UPhysicsHandleComponent* PhysicsHandle = nullptr; 

UInputComponent* InputComponent = nullptr;

// Ray-cast and grab what's in reach
void Grab();

};

Privacy & Terms