Why not use PullTrigger from Gun directly?

Right now Shoot function in ShooterCharacter does nothing but calls the PullTrigger function from Gun. Why not use PullTrigger from Gun directly in BindAction?
I tried doing it but compilation failed because: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Can someone explain me why this happens?

Thanks in advance.

I assume you have written

PlayerInputComponent->BindAction(TEXT("Fire"), IE_Pressed, this, &AGun::PullTrigger);

The problem with that is this is not AGun so the code where InputComponent is trying to call the function on that instance the types don’t match. It should be

PlayerInputComponent->BindAction(TEXT("Fire"), IE_Pressed, Gun, &AGun::PullTrigger);

And the problem with that is the Gun is spawned after SetupPlayerInput. So at that point that would be passing in nullptr.

1 Like

Thank you. Now it is all clear.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.