Generate / override inputs through code?

Does the new Input System have a method for programmatically invoking InputActions?

Use case: after scene load, have the player move left for a set amount of time.

I’m wondering if this can be done without creating a wrapper for every input.

You should read this thread and see this post specifically.

The short answer to your question, however, is no.
There is no way to synthesize an InputAction’s inputs directly. Currently, the only way to synthesize inputs is at the InputDevice level.

I actually did just that when I encountered this problem (I was working on A.I. controlled players). :sunglasses:
It was not a fun process, let me tell you.

Hey, @Rene-Damm ?
I know you are currently working on finalizing the 1.1 release of the Input System (and then you are going to work on backports), but could a feature such as the one described here and here be on the list of features for 1.2?

There’s an item in the list for having a look at this but no timeline for when this would get picked up. There is some stuff happening around OpenXR, though, that will quite likely require revising some fundamentals of InputActions so could well be this is getting picked up as part of that.

For now, while it does require an InputDevice, setting up a mock one actually only requires a couple lines of code. I’ve added a gist here that shows how to do it. See the SetUpMockInputForActions function.

With that function, you could easily switch any PlayerInput, for example, to “mock” input.

void SetUpMockInput(PlayerInput player)
{
    var mockDevice = SetUpMockInputForActions(player.actions);
    player.SwitchCurrentControlScheme("MockInput", mockDevice);
    player.neverAutoSwitchControlSchemes = true;
}

Bit of a roundabout way but doable.

1 Like