InputComponent doesn't work

Hi

I want to make a simple first person shooter but I have some problems with the axis and action binding.
To bind the functions LookUp and OnFire dosn’t work but the rest does. I althoug doesn’t get any compiling errors. I recompiled and reopened the unreal editor and vs, but it didn’t worked.

AFps is a Character and this is the code in FpsChar.cpp to bind the functions.

void AFpsChar::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
	
	check(InputComponent);

	InputComponent->BindAxis("MoveForward", this, &AFpsChar::MoveForward);
	InputComponent->BindAxis("MoveRight", this, &AFpsChar::MoveRight);
	InputComponent->BindAxis("LookUp", this, &AFpsChar::LookUp);
	InputComponent->BindAxis("LookRight", this, &AFpsChar::LookRight);
	InputComponent->BindAction("sayHi", IE_Pressed, this, &AFpsChar::SayHi);
	InputComponent->BindAction("Jump", IE_Pressed, this, &AFpsChar::StartJump);
	InputComponent->BindAction("Jump", IE_Released, this, &AFpsChar::StopJump);
	
	InputComponent->BindAction("Fire", IE_Pressed, this, &AFpsChar::OnFire);
}

This is the declarations off the functions OnFire and LookUp in the .h

void LookUp(float fVal);

void OnFire();

And this is the definition for the functions in the .cpp

void AFpsChar::LookUp(float fVal)
{
	GEngine->AddOnScreenDebugMessage(1, 1.5, FColor::Black, "lookUp");
	//lets the cam look up
	AddControllerPitchInput(fVal);
}
void AFpsChar::OnFire()
{
	GEngine->AddOnScreenDebugMessage(1, 1.5, FColor::Black, "OnFire");
	
	if (projectileClass != NULL)
	{
		//get controlrotation and save in var
		const FRotator spawnRotation = GetControlRotation();
		
		//get the location where the projectile should be spawnd
		const FVector vSpawnLocation = ((projectileSpawnPosition != nullptr) ? projectileSpawnPosition->GetComponentLocation(): GetActorLocation());
		
		UWorld* const world= GetWorld();
		if (world != nullptr)
		{
			//spawn projectile at location
			world->SpawnActor<AFpPronectile>(projectileClass, vSpawnLocation, spawnRotation);
		}

	}
}

I if you have any idea I would be happy for it.

Thanks : )

Just a really dumb question: You did define those in your InputMappings in the ProjectSettings, right? (sorry, right now the only idea i have) :wink:

Hey 143258-

For your LookUp function, are you adding an override for AddControllerPitchInput() somewhere in your class? This function exists in the default APawn class so, given your current setup, you would need APawn::AddControllerPitchInput(fVal); inside your function. Alternatively, you can set the binding to call this function directly with InputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);

I do have a question about your OnFire function. Is the issue that OnFire appears on screen but you don’t get a projectile to actually spawn? Or does OnFire not print at all? If the first situation is the issue, the projectileClass or “world” variable may not be getting set properly. You could add additional debug messages to check if this is the case. If you are not getting the OnFire message to appear at all then the issue may be something else (possibly that the input is not setup properly in the editor as indygoof mentioned).

I did what you said and it still doesn’t work. : (

The OnFire function dosen’t print the texte “OnFire” on the screen.

But this works and AddControllerYawInputis although a childfunction from the pawn class.

void AFpsChar::LookRight(float fVal)
{
	//lets the cam look right left
	AddControllerYawInput(fVal);

And I define the them in my InputMappings in the ProjectSettings and copied the names to make shure that I don’t make spelling mistakes. : )

Another try: On your pawn in the editor, do you have “Use Controller Pitch Input” ticked? I think (!) as a default only the “Use Controller Yaw Input” is ticked, so that may be a solution to the one issue you have.

Cheers,

It works thanks a lot : )))
OnFireWorksNowTo. : )

The actual answer that helped, so it would be nice if you could accept it (for others that look at this issue as a reference, and for me and my hunt for the “Answerhub Sage” Badge :wink: ):

Another try: On your pawn in the editor, do you have “Use Controller Pitch Input” ticked? I think (!) as a default only the “Use Controller Yaw Input” is ticked, so that may be a solution to the one issue you have.

Cheers,

But if I would tick UsePawnConreollerPitch input it would mean that every thing rotats I have to tick it in the camera details panel only.