Hello friends!
I’m trying to create a Player Pawn that binds the Click action of the mouse to a function called SelectAtClick. I’ve been taught that if a method is not altering its own class, to mark it as const. With SelectAtClick, all the method does is perform a raycast from mouse position to see what’s been hit so, based off this guideline, it should be marked as const. However, if I try to mark SelectAtClick as const, the BindAction does not work and I get the following error.
C2664 'FInputActionBinding &UInputComponent::BindAction<APlayerPawn>(const FName,const EInputEvent,UserClass *,void (__cdecl APlayerPawn::* )(FKey))':
cannot convert argument 4 from 'void (__cdecl APlayerPawn::* )(void) const' to 'void (__cdecl APlayerPawn::* )(void)'
My code for binding the Click action:
PlayerInputComponent->BindAction("Click", IE_Pressed, this, &APlayerPawn::SelectAtClick);
My method declaration:
virtual void SelectAtClick() const;
I’ve done some searching online, but haven’t found a way to get around this error. It’s not essential that I mark it const, but it would keep my coding consistent. (During my refactoring, I came across it and thought “Why didn’t I const this?”)
Any insight anyone can provide is greatly appreciated!
Thanks!