Can I trigger an input Action from C++?

For example if I have “Fire Missle” input Action that’s bound to the ‘e’ key.

I have a blueprint that handles the “Fire Missle Event”.

I want to be able to trigger the “Fire Missle Event” from my c++ code just as if the player had pressed the ‘e’ key.

Is this possible?

#Handle Input in Player Controller C++

you can handle any input in C++ in your player controller class like this

WasInputKeyJustPressed(EKeys::E)

#C++ as Foundation

it is better to build the foundation in C++

and then use a blueprint callable function or a BlueprintImplementable event to trigger the blueprint nodes

#Wiki tutorial

BlueprintImplementableEvent

#PS

This only applies to people wanting to use both c++ and blueprints

I’d agree with Rama that you’re probably best off implementing something along the lines of a “On Missile Fired” blueprint implementable event and then binding the E key to a C++ function that fires that instigates that event.

However, for fun and education, there are a couple of ways you could do it, though they aren’t the prettiest :slight_smile:

An example is if you iterate through your input component’s Key or Action bindings as appropriate and find the binding you could then manually call .Execute() on the Delegate associated with it.

I scraped together a probably awful way of doing it but it worked for me.

The console allows you to trigger Custom Events by entering “CE eventname”. In my level blueprint I added the custom event “Fire Missle”. To execute the console command from c++ I did:

GEngine->GetFirstLocalPlayerController(GWorld)->ConsoleCommand(TEXT(“CE “Fire Missle””), true);

EDIT: I’m going to convert this over to use a BlueprintImplementableEvent as suggested by Rama. I think I just have to reparent my Level blueprint.

Thanks guys!