Error: Cannot convert argument 4 from void to FName (Can't migrate to TObjectPtr)

I am trying to migrate over to TObjectPtr, but I get an error if I change the variable from a raw pointer to a TObjectPtr.

No Error

UScanActorComponent* ScanActorComponent;

//Binding function from ScanActorComponent to MyPlayerController`s Input Action
void MyPlayerController::SetupInputComponent()
{
    EnhancedInputComponent->BindAction(IA_Scan, ETriggerEvent::Started, ScanActorComponent, &UScanActorComponent::StartScan);
}

Error if changed to TObjectPtr

TObjectPtr<UScanActorComponent> ScanActorComponent;
Error C2664 : 'FEnhancedInputActionEventBinding &UEnhancedInputComponent::BindAction(const UInputAction *,ETriggerEvent,UObject *,FName)': cannot convert argument 4 from 'void (__cdecl UScanActorComponent::* )(void)' to 'FName'

Does this work:

EnhancedInputComponent->BindAction(IA_Scan, ETriggerEvent::Started, ScanActorComponent, "StartScan");

Oh that seemed to fix the error! Thanks.

Could you explain why using the FName is necessary? I was hoping to avoid using FNames, in case I had to refactor and change some stuff. Are TObjectPtrs not compatible with input binding?

EDIT:
The error went away, but after testing the the input, the input is not detected. It seems like the UObject that has to be bound must be a raw pointer :cry:

EDIT to EDIT:
The code @Extrone gave had no problems, just needed to tag the Member function with UFUNCTION, now that it’s binding by the function name.

The code builds properly when binding by the function name but the input is buggy for some reason and doesn’t respond to the keys sometimes. I suppose just using a regular raw pointer is solution, as opposed to using a TObjectPtr.

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