Input System - How do I detect a Hold with InputAction.ContextCallback?

Hey everyone,

So I’ve been mapping everything to delete an object…
public void DeleteObject(InputAction.CallbackContext context) {
if (context.performed) {
doThing
}
}

This has worked wonderfully for my gamepad buttons and mouse clicks… However, on mobile, I am using taps for other stuff and wanted to use holding.

Is it possible to use the Hold feature the same way or do I need to use a logic gate in Update and all this other hoopla?

Bump.
I’m still stuck on this problem. I can use the old Input system, detect hold in Update and call a DeleteObject() with no CallbackContext, but I’d like to keep things the same and on the new system.

I haven’t had any luck catching a Hold with CallbackContext. I can’t find any tutorials on Hold specifically, just brief rundowns of all the choices in the System.

These guys might know:

https://docs.unity3d.com/Packages/com.unity.inputsystem@1.5/manual/Interactions.html#hold

Adding a Hold interaction should be all you need. You’ll get a performed callback once the input is held down for long enough.

What are you doing to handle the tap inputs? This should be very similar.

I should point out that InputAction.CallbackContext is just something that gets passed to anything you register to receive events (whether directly via something like jumpAction.performed += (context) => Debug.Log("HI!");, or by adding an event to the PlayerInput component). So you won’t really do anything special to handle a hold.

1 Like

Thanks Kurt, didn’t realize and I’m new to the forum.

I tested my code, it worked. I didn’t change anything. I’m not entirely sure what or why? I was simultaneously tackling a separate issue and getting very frustrated… Perhaps I was just getting myself mixed up. Thank you so much for your reply!

1 Like