Search Unity

How to assign Control Scheme and Pairwith Device after instantiate?

Discussion in 'Input System' started by Dakiu, Jan 25, 2020.

  1. Dakiu

    Dakiu

    Joined:
    Dec 12, 2013
    Posts:
    4
    Hello,

    I know that you can assign the controlScheme and pairWithDevice in the instantiate like this:

    Code (CSharp):
    1. PlayerInput.Instantiate(playerPrefab, controlScheme: "p1", pairWithDevice: Keyboard.current)
    However my question is how to do it after the instantiation.


    Code (CSharp):
    1. GameObject player=PlayerInput.Instantiate(playerPrefab, controlScheme: "p1", pairWithDevice: Keyboard.current)
    2.  
    3. player.controlScheme ???
    4. player.pairWithDevice ????
    Is this possible?
    I'm new with this player input, sorry if this was already asked.

    Thanks in advance,

    Regards,
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Code (CSharp):
    1. player.SwitchCurrentControlScheme("Keyboard", keyboard.current);
    To tweak device pairing separate from control schemes, you can also grab the player's InputUser available from PlayerInput.user (that's the piece that actually keeps the majority of a player's state).
     
    Dakiu likes this.
  3. Dakiu

    Dakiu

    Joined:
    Dec 12, 2013
    Posts:
    4
    Great!

    Thanks a lot!