Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Check if context's action equals to defined action map.

Discussion in 'Input System' started by LucianoMacaDonati, Jun 3, 2020.

  1. LucianoMacaDonati

    LucianoMacaDonati

    Joined:
    Dec 31, 2012
    Posts:
    10
    Code (CSharp):
    1. [SerializeField]
    2. private InputActionAsset inputAsset;
    3.  
    4. private RoastsInput.RoastMapActions roastInput;
    I don't know where/how to initialize
    roastInput
    (the auto-generated class from the InputActionAsset) so that I can use it to compare it to the context, like attempted below:


    Code (CSharp):
    1. public void OnSkillUse(InputAction.CallbackContext context)
    2. {
    3.     if (context.performed)
    4.     {
    5.         if (context.action == roastInput.UsePrimarySkill)
    6.         {
    7.             Debug.Log("Primary Skill");
    8.         }
    9.      }
    10. }
    Is there a better way of doing this?
     
    Last edited: Jun 3, 2020
  2. LucianoMacaDonati

    LucianoMacaDonati

    Joined:
    Dec 31, 2012
    Posts:
    10
    Managed to achieve somewhat what I needed doing:

    Code (CSharp):
    1. private RoastsInput roastInput;
    2.  
    3. private void Awake()
    4. {
    5.      roastInput = new RoastsInput();
    6.  
    7.      primaryID = roastInput.RoastMap.UsePrimarySkill.id;
    8.      secondaryID = roastInput.RoastMap.UseSecondarySkill.id;
    9. }
    But it looks bad to me.... Why would I call new on something that is know and it wont change before runtime? Those Guid (ID's) don't seem to change (ran the code several times and those numbers don't change from one execution to the next), so could I just look them up before runtime and save them somewhere?

    It simply seems like a lot of work to get that info at runtime when clearly is know beforehand... Would aprecciate some insight on this. Thanks!