I see that AActor already includes a public member of InputComponent of type UInputComponent.
An UActorComponent seems to always always be a component of an AActor (GetOwner()
return type is AActor*
), wouldn’t it be better performance wise to directly use GetOwner()->InputComponent
instead of searching component by class like in the course, ie GetOwner()->FindComponentByClass<UInputComponent>()
?
For example:
if (GetOwner()->InputComponent)
{
UE_LOG(LogTemp, Display, TEXT("Grabber: InputComponent found on owner %s"), *GetOwner()->GetName());
GetOwner()->InputComponent->BindAction("Grab", IE_Pressed, this, &UGrabber::Grab);
}
For me this worked. We can still affect it to a private member if we don’t want to call GetOwner() each time.
Thanks!