Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Looking for Callback Context on a player input object

Discussion in 'Input System' started by notMateo, Jan 30, 2020.

  1. notMateo

    notMateo

    Joined:
    Mar 2, 2018
    Posts:
    37
    Me and friend are trying to figure out how to get a callback context from a Game Object using a Player Input component to get the device of the button that has been pressed, if it's possible?

    Basically I'm trying to get some multiplayer functionality going. When I press a face button, I need to get which controller pressed said button and return the device. This is what we tried so far:

    Code (CSharp):
    1.     void MyButtonPress(InputAction.CallbackContext ctx)
    2.     {
    3.         InputDevice device = ctx.control.device;
    4.         Debug.Log(device);      
    5.     }
    This is what my friend came up with, but I wanted to do this within the method called by the Player Input (MyButtonPress, in the example above)

    Code (CSharp):
    1.     void Awake()
    2.     {
    3.         ctrl.Ctrl.Act.performed += ctx => onButtonPress(ctx);
    4.     }
    5.  
    6.     void onButtonPress(InputAction.CallbackContext ctx)
    7.     {
    8.         InputDevice device = ctx.control.device;
    9.         Debug.Log(device);
    10.     }
     
  2. syphase

    syphase

    Joined:
    Jun 21, 2021
    Posts:
    2
    I am having the same issue. I want to be able to get the specific PlayerInput that called the action.