how to switch the "Actions Asset" in the Input System UI Input Module at runtime

Hello guys,

I am trying to switch the “Actions Asset” in the Input System UI Input Module (script) at runtime so the user can choose to control the game with a gamepad or a keyboard and mouse from an options screen. But when I switch the “Actions Asset” the UI stops responding to either input Actions Asset.

I am trying to use the “VirtualMouseInput” from Unity’s samples project, so when using the gamepad, the user can control a virtual mouse cursor with the gamepad.

Could anyone help?

Regards,
Carlos

1 Like

Hey,

Did you ever find the solution to the UI not responding after changing the actions asset?

Thanks,
Ashley

InputSystemUIInputModule only does limited lookups on the actions when an asset is assigned to it. For any action that is referenced, it will go and find an action with the same path.

So if you have point set to UI/Point and you assign a new asset, it’ll try to find UI/Point in the asset. But if point is not set, it will not try to find a UI/Point action in the asset and you have to manually set that if you want it referenced.

var actions = new MyGeneratedActionClass();

var uiModule = (InputSystemUIInputModule)EventSystem.current.currentInputModule;
uiModule.point = InputActionReference.Create(actions.UI.Point);
uiModule.leftClick = InputActionReference.Create(actions.UI.Click);
1 Like