Search Unity

Is it possible to create Action bind to custom "game events" ?

Discussion in 'Input System' started by bali33, Jul 3, 2020.

  1. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hello,

    I was wondering if I could create an "Jump" action that would be triggered when the player presses a button on a touch screen (mobile screen) ? When it comes to mobile lot of inputs are virtual inputs and I'd like to be able to bind interactions/combinations of those inputs to Actions.

    Is that possible ?

    Thanks.
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    A button like for on-screen joysticks? If so, see here. With the on-screen controls, you can set up a binding for the gamepad A button, for example, and then have an on-screen button correspond to the A gamepad button.
     
  3. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hello @Rene-Damm ,

    So it's not really what I want. I'd like to be able to bind and action to one ore more on-screen controls. Could be useful to be able to trigger an Action like "InventoryItemSelected" when an inventory item is clicked for example. So it's not like each inventory item could be bind to a gamepad button.

    Does that make sense ? Is it doable ?

    [EDIT]
    After reading the doc. Would it possible (using the inventory example) to have the inventory being a CustomControl set used the "SendValueToControl" to pass-in an object or an id or whatever ?

    Thanks
     
    Last edited: Jul 8, 2020
  4. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Seems like it would make more sense to just use plain UI objects as is in this case. Routing the UI input into InputActions will result in any contextual data being lost and there doesn't seem to be a benefit of picking up this kind of input through the action input path.

    An inventory button as a UI button could simply be bound to "InventoryItemSelected" with a string or int as a parameter to identify the button/item.
     
  5. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Yes it could. But I thought that an UI button is kind of an Input. And then it would have (may be) makes sense to treat it like an Input and try to handle it through the new Input system. That way code can listen to the input instance class rather than listen to specific UI events. Would have been a way to decouple a bit from the UI.

    But maybe it's a bad idea.