Download

Control a StaticMeshActor with an ActorComponent

I am pulling out my hair trying to get this to work and don’t know why it is so difficult.

I have a simple staticmesh actor that is in the scene already created and I added a C++ component to it.
It is of a class UActorComponent.

I’d like to control it through keyboard events. I set it up already in the project settings.

How do I bind the keyboard events into my UActorComponent class?

InputComponent isn’t visible in my class.

What is the correct way to handle and receive keypresses in my actor?

I haven’t tried this yet. But what I would do is have the parent class setup or pass the input component to the child via reference. Either pass a variable UInputCompent via a function or have the class use the FindComponentbyClass<UInputComponent>(). Also, try GetOwner()->InputComponent

I would have though you would need to make your simple static mesh actor a pawn and possess/un-possess it as required.

It seems that is one of the big differences between a mere actor and a pawn.

Try adding the Input binding in your Character’s BeginPlay like this:

if(InputComponent != NULL)
{
	InputComponent-&gt;BindAction("Action", IE_Pressed, YourComp, &YourSceneComponent::OnPress);
}

and have a variable USceneComponent* YourComp set.