Search Unity

Question Using Player Input with Send Messages

Discussion in 'Input System' started by GlenZPS, Nov 27, 2020.

  1. GlenZPS

    GlenZPS

    Joined:
    Sep 12, 2019
    Posts:
    25
    Before Player Input, I use inputActions.Player.Move.canceled to cancel movement when releasing move button, since now I am using player input with send messages, I changed the name of the method to OnMove, but how do I know when a button is released?
     
  2. FileThirteen

    FileThirteen

    Joined:
    Oct 23, 2012
    Posts:
    40
    With send messages it is calling the method up to 3 times when the action is started, performed, and cancelled based on how you have your Input Action Asset set up for that particular action. For example if you have it set up as a Action Type as Button with Press and Release Interaction then your method will be called twice when you press the button down and once as soon as you release it. Inside your method you need to interrogate the InputAction.ContextCallback to find out what phase it is (started, performed, or canceled) and then decide what to do inside of your method based on the phase.

    With your OnMove I'm guessing it's either an Action Type Value and Control Type Vector2 or Action Type Value and Control Type Axis. If you have your Action set up as either of those with no Interaction set up then it should be as follows: started on any joystick movement, performed while joystick is not centered over and over every frame, and canceled when release joystick or recenter the joystick.
     
    jdigi78 likes this.
  3. GlenZPS

    GlenZPS

    Joined:
    Sep 12, 2019
    Posts:
    25
    I know it takes in InputAction.ContextCallback when i'm using Player Input with unity events, is it also the same with Send messages?
     
  4. FileThirteen

    FileThirteen

    Joined:
    Oct 23, 2012
    Posts:
    40
  5. jjc6252498

    jjc6252498

    Joined:
    Oct 11, 2021
    Posts:
    2
    + Button Down Up Check
    upload_2022-10-4_14-48-53.png

    upload_2022-10-4_14-49-3.png