Problem with UInputController v 4.17.1

Hi, I have issues when creating InputComponent, in this line:
InputComponent = GetOwner()->GetComponentByClass<UInputComponent>();

The error is: "UInputComponent not a valid expression type"
I already tried to include the InputComponent header (#include "Components/InputComponent.h" ) but this seems to not resolve my problem!
@DanM

Any suggestions?
Thank you,
Luca

code?

I’m sorry, I forgot to send that.

Grabber.cpp

#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.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


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

	UE_LOG(LogTemp, Warning, TEXT("Grabber READY!!!"));
	
	PhysicHandle = GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();
	if (!PhysicHandle)
	{
		UE_LOG(LogTemp, Warning, TEXT("PhysicHandle not connected to the object %s"), *(GetOwner()->GetName()))
	}

	AActor* Owner = GetOwner();
	InputComponent = Owner->GetComponentByClass<UInputComponent>();
}


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

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

	/*UE_LOG(LogTemp, Warning, TEXT("ViewPoint position: %s, rotation: %s."), *PlayerViewPointLocation.ToString(), *PlayerViewPointRotation.ToString());
	int a;*/

	FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() *reach;
	DrawDebugLine(GetWorld(), PlayerViewPointLocation, LineTraceEnd, FColor(255, 0, 0), false, 0.f, 0.f, 10.f);

	FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());

	FHitResult hit;
	GetWorld()->LineTraceSingleByObjectType(
		OUT hit,
		PlayerViewPointLocation,
		LineTraceEnd,
		FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
		TraceParameters
	);

	AActor* ActorHit = hit.GetActor();
	if (ActorHit)
	{
		UE_LOG(LogTemp, Warning, TEXT("Object: %s"), *(ActorHit->GetName()));
	}
}

Grabber.h

#pragma once

#include "Engine.h"
#include "Components/ActorComponent.h"
#include "Components/InputComponent.h" 
#include "PhysicsEngine/PhysicsHandleComponent.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();

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 reach = 100.f;

	UPhysicsHandleComponent *PhysicHandle = nullptr;
	
	UInputComponent *InputComponent = nullptr;
};

Sorry I didn’t realise you replied. Use FindComponentByClass not GetComponentByClass

Oh it’s because I had some problems with IntelliSense so I wrongly wrote the method! Now all work.
Thank you and sorry for the waste of time.

Privacy & Terms