Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Arbitrary Inputs to Anonymous Actions

Discussion in 'Input System' started by templewulf, Dec 22, 2016.

  1. templewulf

    templewulf

    Joined:
    Dec 29, 2013
    Posts:
    52
    I'm working on a game with assignable abilities of arbitrary number. For example, think of how players can assign different items to arbitrary buttons in games like The Legend of Zelda: Ocarina of Time.

    In my current design, the player can collect any number of abilities to be assigned to 1-5 slots on the player's avatar. So, we have arbitrary abilities, number of slots, and buttons, all changeable at run-time.

    My goal is to set up a menu with ability icons and a cursor. The player moves the cursor around the menu and presses the button they want to use for the highlighted ability.

    I've seen how the demo uses BindControl and ListenForBinding to assign arbitrary buttons to specific actions. Can I add and use actions in a more anonymous way? Is there an example for such a thing?
     
  2. templewulf

    templewulf

    Joined:
    Dec 29, 2013
    Posts:
    52
    Also, it occurs to me that one thing that might help is a list of currently bound InputControls. If I have "fire", "pause", "run", etc. in an ActionMap asset, they get added as properties to my generated ActionMapInput subclass. But I have no idea how to iterate over them.

    Ideally, I could store an InputControl in a map, check that map during the normal input checks in Update(), do the normal isHeld() checks during Update() and call the ability that way.

    For now, I'd have to figure out a pre-designed maximum number of "ability slots" that a player could conceivably have, add those to the action map, and check each one of them for adding to the map. Then, re-bind them at run-time when the player wants to change ability assignments.

    I'm still thinking this through, so any further suggestions are very welcome!
     
    Last edited: Dec 22, 2016
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    If you have maximum 5 slots, I would add an action in the ActionMap for each of the 5 potential slots. If it's an unlimited amount of slots, and you want to specifically add new actions at runtime, then that's not a scenario we have designed for so far. It might be possible already, or simple for us to add support for, but I can't say off the top of my head if this will be the case.
     
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    The subclass has a controlCount property and you can access individual controls using element access notation, e.g. myActionMapInput[5] for the control with index 5.
     
  5. templewulf

    templewulf

    Joined:
    Dec 29, 2013
    Posts:
    52
    Oh! I somehow hadn't realized that you could use array notation on the ActionMapInput subclass! I was expecting a property that returns an array or something. I appreciate the heads up.

    For the rest, I was looking for a more code-focused solution rather than having to specifically plan for input "slots". For practicality, the current demo has the 360 gamepad in mind, hence the 5 ability limit. Thinking ahead for something keyboard controls, I don't want to define 20 keys for abilities when that happens.

    That said, I always preferred gamepads anyway, so I'll just go with your suggestion. Thanks for reading! :)