Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rebinding does not work if you are using c# events on a newly created instance. Intentional?

Discussion in 'Input System' started by Yukken, Feb 4, 2021.

  1. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    93
    I was implementing rebinding on my game based on the rebinding example but it didn't work. I wondered why until I ran this test.
    Code (CSharp):
    1. GameplayInput OldAsset;
    2.  
    3. void Awake(){
    4.             gameplayInput = new GameplayInput();
    5.             Debug.Log(OldAsset== gameplayInput.asset);
    6. }
    Gameplay input is the generated c# class for the input asset.

    The comparison produces false. I realized that the new object for the auto generated c# class does not point to the same asset as the one in your project folder before hitting playmode. In fact, it is different for every new object created through new GameplayInput().

    After rebinding, the original asset gets binding overrides but the c# version does not. If I loop through the C# object.bindings, I don't get anything in the overridepath.

    On the other hand, the rebinding in the example seems to be done on a per asset basis. It used the reference of the old asset. It was rebinding the old asset values again and again but obviously it had no effect. Unless I forcefully update all of them every time a rebind happens.

    What is the recommended way to handle input if this approach is unsuitable for rebinding? InputActionReference seems to be tightly bound to a particular input asset. So I assume it's going to work fine with rebinding?

    If that is indeed the recommended way to handle input, then I really do think Unity should make that clear. The new input system can be used in a bazillion ways but if most of them are unscalable, then there is clearly a problem.

    My project is at a late stage and this type of change will take time. Moreover, I think a lot of devs can run into this pitfall. My first introduction to the new input system, as with many, was a Brackeys video that showed the approach I used.
     
    Last edited: Feb 5, 2021
  2. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    93