Code don't get Input Component

Hi! I’m using UE 4.17, I have my SetInputComponent method like this:

void UGrabber::SetInputComponent()
{
InputComponent = GetOwner()->FindComponentByClass();
UE_LOG(LogTemp, Error, TEXT(" %s"), InputComponent);
if (InputComponent)
{
InputComponent->BindAction(“Grab”, IE_Pressed, this, &UGrabber::Grab);
InputComponent->BindAction(“Grab”, IE_Released, this, &UGrabber::Release);
}
else {
UE_LOG(LogTemp, Error, TEXT(" %s: falta el componente de entrada "), *GetOwner()->GetName());
}
}

And it should work but on the runtime I get the error message even though my character has the input component:
Captura

Why I don’t get the InputComponent on code even though it is on the character?

Im not very good at explain this but your missing

InputComponent = GetOwner()->FindComponentByClass<UInputComponent>();

hopefully this works for you and here is some more info:
Here
Have a little read of that see if you can make sense of it
Good luck!

Oh yeah, I had it that way I just don’t know Why did I copy that wrong in here. I’ll check the page anyway, thank you.

Oh my fault I misread your question i think its to do with

InputComponent = GetOwner()->FindComponentByClass();
UE_LOG(LogTemp, Error, TEXT(" %s"), InputComponent);
if (InputComponent)

Try and remove that UE_LOG then you will only get a error when its not included on your pawn

I had that UE_LOG to see if InputComponent was assigned a value, by some reason if I put it as a Warning my project crasshes.

On my code I had the declaration as this:

InputComponent = GetOwner()->FindComponentByClass< UInputComponent>();

but it don’t assign any value (it stays as null), and in comparision the FindPhysicsHandleComponent() it assigns a value to the physics handler like this:

PhysicsHandle = GetOwner()->FindComponentByClass< UPhysicsHandleComponent>();

and that variable has a value… I don’t know why I don’t get a value on InputComponent if in theory both methods had the same value declarations and one of them get a value while the other doesn’t.

do you have

class UPhysicsHandleComponent* PhysicsHandle = nullptr;

class UInputComponent* InputComponent = nullptr;

in your .h file?

heres is my code for them both
InputComponent

void UGrabber::SetupInputComponent()
{
	InputComponent = GetOwner()->FindComponentByClass<UInputComponent>();
	if (InputComponent)
	{
		InputComponent->BindAction("Grab", IE_Pressed, this, &UGrabber::Grab);
		InputComponent->BindAction("Grab", IE_Released, this, &UGrabber::Release);
	}
	else
	{
		UE_LOG(LogTemp, Error, TEXT("%s Missing input component"), *GetOwner()->GetName())
	}
}

PhysicsHandle

void UGrabber::FindPhysicsHandleComponent()
{
	PhysicsHandle = GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();
	if (PhysicsHandle == nullptr)
	{
		UE_LOG(LogTemp, Error, TEXT("%s Missing physics handle component"), *GetOwner()->GetName())
	}
}

Have a read threw it and see whats going wrong for your self don’t just copy and paste :stuck_out_tongue:

I had them exactly the same as you do, but I still get the error. I’m watching the IWYU video on the course, hope that will help.

If you click on the link i said in the first comment and scroll to the bottom you will find what you need to include there :slight_smile:

Privacy & Terms