PressInteraction and how to make it work

Hi, I have to preface this by saying I really like the way the new Input System is turning out.

I am trying to figure out how to get my button only to fire once per press. I found the interactions section in the Input Actions Editor. So I added the PressInteraction and saved the asset.

However, in the callback of my action, it is still called called multiple times.

        public void OnJump(InputAction.CallbackContext context)
        {
            if (context.performed) {
                _jump = context.ReadValue<float>() != 0f;
            }
        }

Here is my Input Actions


This should work. What do you mean is called multiple times? OnJump? Or the part inside if (context.performed) {?

The callback is still called multiple times, even when I add the conditional

2 Likes

Hmm, i have the same code here, and it works fine for me. You will need to submit a bug report with a repro project and post the case number here, so we can take a look.

I figured out the problem, after attempting to re-create the project. It was not with the Input System, but user error. :smile: Press Iteraction is working as intended.

This leads to another question. If this isn’t the right forum, let me know. I want to know properly how to know if the player is jumping. I am having a problem to know when to properly set the _jump in my JobComponentSystem bool to false. Here is some context:

I know when the user presses the jump button:

  public class CharacterControllerSystem : JobComponentSystem, IGameplayActions
    {
        private bool _jump;
       ...
        public void OnJump(InputAction.CallbackContext context)
        {
            _jump = context.ReadValue<float>() != 0f;
        }
     }

I send the '_jump" same input to my job:

 protected override JobHandle OnUpdate(JobHandle inputDependencies)
        {
            var phyicsJob = new CharacterControllerPhysicsJob {
               ...
            };

            inputDependencies = phyicsJob.Schedule(this, inputDependencies);
            inputDependencies.Complete();

            var controllerDataType = GetArchetypeChunkComponentType<CharacterControllerData>();
            var physicsColliderType = GetArchetypeChunkComponentType<PhysicsCollider>();
            var physicsVelocityType = GetArchetypeChunkComponentType<PhysicsVelocity>();
            var translationType = GetArchetypeChunkComponentType<Translation>(true);
            var rotationType = GetArchetypeChunkComponentType<Rotation>();
            var isGamepadConnected = Gamepad.current != null;

            var job = new CharacterControllerSystemJob {
                MoveDir = _move,
                Jump = _jump,
                ShootDir = _shootDir,
                DeltaTime = Time.deltaTime,
                GamepadConnected = isGamepadConnected,
                CharacterControllerType = controllerDataType,
                PhysicsColliderType = physicsColliderType,
                PhysicsVelocityType = physicsVelocityType,
                TranslationType = translationType,
                RotationType = rotationType
            };

            return job.Schedule(_group, inputDependencies);
        }

In the Character Controller System Job, I check to see if the player is jumping. The character does jump. No matter what I do, I either see the player fly off or not move.

     if (characterData.IsJumping) {
         linearVelocity.y += characterData.JumpSpeed;
         characterData.IsJumping = false;
         }