Search Unity

Why SetCallbacks release former bindings?

Discussion in 'Input System' started by zYmqwert, Mar 10, 2020.

  1. zYmqwert

    zYmqwert

    Joined:
    Feb 23, 2017
    Posts:
    5
    Version: Input System Preview 4

    In InputAsset's auto generate codes,
    I found that SetCallbacks will release the previously bound interface before binding the new interface,
    This makes it impossible to bind more than one object with it .
    Hope someone can tell me why and how to bind more than one object.

    Code (CSharp):
    1. public void SetCallbacks(IGameplayActions instance)
    2.         {
    3.             if (m_Wrapper.m_GameplayActionsCallbackInterface != null)
    4.             {
    5.                 @MoveHorizontal.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMoveHorizontal;
    6.                 @MoveHorizontal.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMoveHorizontal;
    7.                 @MoveHorizontal.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMoveHorizontal;
    8.                 @MoveVertical.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMoveVertical;
    9.                 @MoveVertical.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMoveVertical;
    10.                 @MoveVertical.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMoveVertical;
    11.             }
    12.             m_Wrapper.m_GameplayActionsCallbackInterface = instance;
    13.             if (instance != null)
    14.             {
    15.                 @MoveHorizontal.started += instance.OnMoveHorizontal;
    16.                 @MoveHorizontal.performed += instance.OnMoveHorizontal;
    17.                 @MoveHorizontal.canceled += instance.OnMoveHorizontal;
    18.                 @MoveVertical.started += instance.OnMoveVertical;
    19.                 @MoveVertical.performed += instance.OnMoveVertical;
    20.                 @MoveVertical.canceled += instance.OnMoveVertical;
    21.             }
    22.         }