Can't we just use GetOwner()->InputComponent?

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!

Yes, you can. I said the same to Mike, honestly.

Note: This doesn’t necessarily mean that it is actually pointing to an instance of one.

Thank you!

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

Privacy & Terms