How to get InputComponent in C++?

I’ve created a Character blueprint and I’ve attached to it a C++ class that extends the UCharacterMovementComponent class and I’ve overrided the OnRegister function. From here I want to get the UInputComponent on the character (which I’m pretty sure all characters have, right?) so I tried adding

TArray<UInputComponent*> comps;
GetComponents(comps);

But I get an error stating that GetComponents cannot be found. Is there some other way I can get a handle to the InputComponent?

Getting the input component from a Character is very simple, in fact from any Actor that as one! It is a member of every AActor!

From Actor.h :

/** Component that handles input for this actor, if input is enabled. */
	UPROPERTY()
	class UInputComponent* InputComponent;

Basically anywhere in your class:

UInputComponent* myInputComp = InputComponent;

if(myInputComp)
{
//Do whatever with myInputComp if it's valid.
}

Be aware that if that actor does not have an input component, it will obviously be empty, also, the InputComponent may not be created at the start of the class, depending on the logic, so make sure it's valid before using it!

After some more digging around I found that GetComponents can only be called on AActors and from some even more digging around through the source, I found this GetOwner() function that will return the AActor who owns this component. With that I can do

TArray<UInputComponent*> comps;
GetOwner()->GetComponents(comps);

Then loop through the returned array to find the component. But Michaël Dubé pointed out an even simpler way. I can just do

GetOwner()->InputComponent;