Cannot BindAction to &AGun::OnFire

I’ve changed the first person class to Bind its fire action to the gun class function address instead of its own OnFire function. I made sure it was public like in the video, and has the correct name, but it complains that the bind action function cannot do this.

In both unreal editor and in visual studio i get the following build error(s):

2>------ Build started: Project: FPS_Project, Configuration: Development_Editor x64 ------
2>  Compiling game modules for hot reload
2>  Performing 3 actions (4 in parallel)
2>  FirstPersonCharacter.cpp
2>C:\GitHubRepositories\FPS Project\FPS_Project\Source\FPS_Project\Player\FirstPersonCharacter.cpp(129): error C2664: 'FInputActionBinding &UInputComponent::BindAction<AFirstPersonCharacter>(const FName,const EInputEvent,UserClass *,void (__cdecl AFirstPersonCharacter::* )(FKey))': cannot convert argument 4 from 'void (__cdecl AGun::* )(void)' to 'void (__cdecl AFirstPersonCharacter::* )(void)'
2>          with
2>          [
2>              UserClass=AFirstPersonCharacter
2>          ]
2>  C:\GitHubRepositories\FPS Project\FPS_Project\Source\FPS_Project\Player\FirstPersonCharacter.cpp(129): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>ERROR : UBT error : Failed to produce item: C:\GitHubRepositories\FPS Project\FPS_Project\Binaries\Win64\UE4Editor-FPS_Project-822.dll
2>  Total build time: 5.75 seconds (Local executor: 0.00 seconds)
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): error MSB3075: The command ""C:\Program Files\Epic Games\UE_4.15\Engine\Build\BatchFiles\Build.bat" FPS_ProjectEditor Win64 Development "C:\GitHubRepositories\FPS Project\FPS_Project\FPS_Project.uproject" -waitmutex" exited with code 5. Please verify that you have sufficient rights to run this command.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


^ You can see in the following screenshot my gun’s OnFire method should be valid, but the compiler still complains


^the red squiggly does appear as so; when i took the first screenshot it randomly dissapeared for a minute though

I managed to use a work around by doing this:

void AFirstPersonCharacter::OnFire()
{
    GunActor->OnFire();
}

But still a mystery as to why the video’s version doesn’t work

Also I should maybe note that ‘Gun’ appears to be some sort of macro word, as it is highlighted in purple. I changed the name to GunActor for clarity, or debugging.

U need to change
BindAction("Fire",IE_Pressed,this,&AGun::OnFire) ;
to
BindAction("Fire",IE_Pressed,Gun/*Points to gun created in Begin method*/ ,
&AGun::OnFire);

Thanks; DanM actually solved this for me on the Q&A, but i forgot to update it here xD.

Somehow I missed that Sam was passing the Gun as an argument.

I thought he was using this which is why I was so confused.

Also, Sam used duplicate names alot, which often sets one up for failure.
It is obvious why this is a bad idea and brain-lapsing.

Privacy & Terms