Search Unity

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

Discussion in 'Input System' started by strongbox3d, Jul 16, 2020.

  1. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    860
    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
     
    Sam_Hedges likes this.
  2. GeekOutGamer

    GeekOutGamer

    Joined:
    Dec 11, 2013
    Posts:
    4
    Hey,

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

    Thanks,
    Ashley
     
  3. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    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.

    Code (CSharp):
    1. var actions = new MyGeneratedActionClass();
    2.  
    3. var uiModule = (InputSystemUIInputModule)EventSystem.current.currentInputModule;
    4. uiModule.point = InputActionReference.Create(actions.UI.Point);
    5. uiModule.leftClick = InputActionReference.Create(actions.UI.Click);
     
    mpriess93 likes this.