Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question How to get a list of Action Maps and the related Actions of each from Input asset?

Discussion in 'Input System' started by ZoidbergForPresident, Jan 6, 2021.

Thread Status:
Not open for further replies.
  1. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    Hi,

    I see that in the generated class from the inputactions asset, there is no list of Action Maps (like player or menu) nor a list of actions for each of them.

    Should I edit the generated class to add those or would it be possible to generate this automatically?

    I'm actually trying to write a tool that'll generate a key rebind screen as it's something that is sorely and too often mised in games.

    Cheers.
     
  2. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    Mmh, issue is this all depends on the generated class, could it be possible to do something like that? Feeding any InputActions asset and get a rebind screen? Even with reflection of some sort? You can't access the asset directly apart from the asset field in the generated class?
     
  3. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    So is there really no way to easily make a reusable rebind screen?
     
  4. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    I see that the generated class for the Input asset implements IInputActionCollection which is an IEnumerable<InputAction> but we can't for-each it...

    I'm at a loss, there really isn't any simple way to go through the different bindings?

    Why such a convoluted way of doing this, there are way too many games that don't bother with keyrebinds (or half ass it), and Unity does not offer an alternative to what they removed.

    What's to do?
     
  5. I'm not sure I understand the problem, the map can be foreached:

    I'm using the Rebinding UI sample from the Package Manager. Select the InputAction asset and generate the C# class too.
    Code (CSharp):
    1. using UnityEngine;
    2. public class RebindForeach : MonoBehaviour
    3. {
    4.     void Start()
    5.     {
    6.         var map = new RebindUISampleActions();
    7.         foreach (var action in map)
    8.         {
    9.             Debug.Log(action.name);
    10.         }
    11.     }
    12. }
    13.  
    Results:
    result.png
     
  6. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    "Rebinding UI sample from the Package Manager"? I don't have this one available.

    As for the issue, I want to make a tool that generates a rebind screen starting from an input asset and for starter I need to go through the actions of each map. Can we do that starting from an input asset or do we HAVE to use the generated class?
     
  7. Doesn't matter.
    Code (CSharp):
    1. var map = new RebindUISampleActions();
    Change it to whatever is your C# class name in the generated C# file. You can refine then if you only want to iterate over one action map.

    result.png
     
  8. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    Strange it didn't work before. Thanks.

    But also we go through all the action maps, any way to go through the maps themselves before then the actions?

    I probably don't understand the whole structure, it seems complicated.
     
  9. Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class RebindForeach : MonoBehaviour
    5. {
    6.     [SerializeField] InputActionAsset actionAsset;
    7.     void Start()
    8.     {
    9.         foreach (var action in actionAsset)
    10.         {
    11.             Debug.Log(action.name);
    12.         }
    13.     }
    14. }
    15.  
    Probably you can filter out the maps too if you want to. Check the documentation.
    Look, it took me 20 minutes or so to get here. When I read your problem I had no idea what the Input System can do. I'm pretty sure if you spend a little bit more time with the documentation and try things out for yourself you can solve whatever problem you have. :)
    So actually this system is super simple and powerful.
     
    ow3n and moose0847 like this.
  10. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    . . .

    You seem to be pretty capable, read this then: once one have all the data for the maps and their actions (which seems pretty nasty to do but whatever) how would one make a tool that'd allow to right click on the Input ASSET and generate a UI panel with all the maps and action?

    The detail can be worked out but starting from the input asset, how one would do it?

    Should take you 3 minutes top.
     
    Last edited: Jan 16, 2021
  11. You're welcome, any time!
     
  12. I won't rob you from the pleasure of solving your own problems, but I can give you an idea how to start,
    First
    upload_2021-1-16_9-37-32.png
    Then, the imported package contains a Prefab "RebindUIPrefab".
    result.png

    That Prefab is for one action rebinding. If you make a UI panel which can contain a list of these like a scroll or whatever, you just instantiate a bunch of those Prefabs and set the "action" property to the action value in the foreach in our above examples.
     
  13. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    Why do you think I post here if not to get help "solving my own problems".

    Go away now.

    As for the decent people here, I'm still open for suggestions. :)

    tldr;
    Starting from input asset, what's the first step for a tool taking it as "input" somehow to generate a rebind screen?
    Is there a way to generalize the code enough to do that?
     
  14. I gave you every help to you to be able to finish your task. I can write the stuff for you, $100 is my hourly rate, min. 1 hour. Hit me up in PM if you're interested.

    Interesting way to say thank you when someone tries to help you...
     
    johnetc likes this.
  15. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    When asking for help, and someone helps you, the appropriate response is "Thank you". Since you are not interested in the help being offered, no point in this topic remaining open. Closed.
     
Thread Status:
Not open for further replies.