Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

PlayerInputManager onPlayerJoined and PlayerInput onActionTriggered

Discussion in 'Scripting' started by TheCellCH, Apr 11, 2020.

  1. TheCellCH

    TheCellCH

    Joined:
    Sep 29, 2017
    Posts:
    5
    Hello everybody

    I am trying to get into the details and implement the new input system in a prototype of mine. For this purpose I wanted to do a turn based game but some events don't really work or don't work the way expected. I hope somebody can explain to me how I am supposed to use them or if it is a bug.

    Bug one is with the PlayerInputManager. I have read the docs (https://docs.unity3d.com/Packages/c...manual/Components.html#notification-behaviors) and I have a gameobject with a player input manager and a script of mine. If I listen to onPlayerJoined I do not get a callback (PlayerInputManager Notification Behaviour set to "Send Messages"). I have to switch the Notification Behaviour to Unity Events and manually reference my script methods for it to work. Is this a bug?

    The Function PlayerManager_onPlayerJoined is never called. Even though the player spawning does work.
    Code (CSharp):
    1. private void Start()
    2.     {
    3.         playerManager = PlayerInputManager.instance;
    4.         // not working
    5.         // playerManager.onPlayerJoined += PlayerManager_onPlayerJoined;
    6.     }
    When referencing it manually with unity events (like in the screenshot) it does get called.
    onplayerjoined_UnityEvents.PNG

    The second thing that is bothering me is in the playerJoined function. I can't get a trigger when I subscribe to onActionTriggered. I have to breadcrumb through PlayerInput.currentActionMap.actions.performed to add a function callback. I either missunderstand the onActionTriggered or it is not working either.

    Code (CSharp):
    1. public void PlayerJoined(PlayerInput input)
    2.     {
    3.         // not working
    4.         // input.onActionTriggered += Input_onActionTriggered;
    5.  
    6.         for (int i = 0; i < input.currentActionMap.actions.Count; i++)
    7.         {
    8.             if (input.currentActionMap.actions[i].name == "Fire")
    9.             {
    10.                 input.currentActionMap.actions[i].performed += SwitchRounds_performed;
    11.             }
    12.         }
    13.     }
     
  2. alexxjaz

    alexxjaz

    Joined:
    Sep 18, 2018
    Posts:
    40
    In case that anyone needs to make it work. Change it to Invoke Csharp Events and it will get called.
     
unityunity