Search Unity

Set InputSystemUIInputModule at Run Time?

Discussion in 'Input System' started by HeavyPepper, Jan 26, 2022.

  1. HeavyPepper

    HeavyPepper

    Joined:
    Jul 12, 2012
    Posts:
    5
    What is the correct way of setting the InputSystemUIInputModule via C#? I've attempted the following without success...

    Code (CSharp):
    1. InputSystemUIInputModule uiModule = GetComponent<InputSystemUIInputModule>();
    2.  
    3. var actions = new MyGeneratedInputSystemClass();
    4.  
    5. uiModule.point.Set(actions.UI.Point);
    As well as...

    Code (CSharp):
    1. ((InputSystemUIInputModule)EventSystem.current.currentInputModule).point = InputActionReference.Create(actions.UI.Point);
    The second gives me an object reference not set error at run time however the IDE shows no issue. I'm unsure which reference is missing?

    My Input Action Map is called "UI" and per this example it includes a "Point" action.


     

    Attached Files:

  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Second method should work fine at least as of 1.3.
     
  3. kloot

    kloot

    Joined:
    Mar 14, 2018
    Posts:
    78
    I need to do the same but changing it in runtime also changes it it editor mode - this is bananas. Does anyone has any ideas as to change this reliably either in runtime or in editor mode?
     
    Last edited: Mar 20, 2024