Search Unity

[Solved] Using Controls rather than paths to compare compostie bidnings

Discussion in 'Input System' started by fredrik_unity363, May 6, 2020.

  1. fredrik_unity363

    fredrik_unity363

    Joined:
    May 4, 2020
    Posts:
    3
    Hey.

    Is there a way to acsess path to a composite in a composite binding in scripts? When you acsess the path of a composite it returns the composite name, While other bindings return the path that the corresponding action is bound to.

    Im using paths to determin wheter two active actions are using the same bindings, and getting a bunch of false positives becasue i have multiple composites of the same type with different bindings.

    there might be some other way to compare what buttons actions are bound to?
     
    Last edited: May 6, 2020
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Which path do you have in mind? Composite bindings don't really have a path like "actual" control bindings do.

    For this particular, simply comparing the controls (InputAction.controls) is probably more effective.
     
  3. fstorehaug

    fstorehaug

    Joined:
    Apr 3, 2017
    Posts:
    10
    @Rene-Damm Thank you for a quick reply!
    I'm looking for the bindings in the composites, for example, the w, a, s,d keys in a standard vector 2 composite, in my case its VR, I need to track the trackpad and trackpad-click. Anyway to get to them will do. I get that the .path variable of a composite cant return the path as any other binding would do. but I find it strange that it returns the name of the binding instead. it's inconsistent? This, however, does not matter to me, as long as I can somehow determine whether two actions are bound to "identical" composites.


    I considered this, and I might be miss reading the documentation, but I think the controls are null until input is registered for that action for the first time, meaning that if a user never hits one of the buttons I'm remapping, I will only find null values there. I tested this, and think I can confirm it? maybe I'm missing something here. posting code and debug message.

    Code (CSharp):
    1. public class debugScript : MonoBehaviour
    2. {
    3.  
    4.     private ControllerInput controllerInput;
    5.  
    6.     private void OnEnable()
    7.     {
    8.         controllerInput = new ControllerInput();
    9.         controllerInput.Enable();
    10.         controllerInput.DesktopActionMap.space.performed += onMouseClickBinding;
    11.     }
    12.  
    13.     private void onMouseClickBinding(InputAction.CallbackContext context)
    14.     {
    15.         Debug.Log("Controlls for debugAction: " + controllerInput.DesktopActionMap.Debug.controls);
    16.     }
    17.  
    18. }
    input actions.PNG

    debug.PNG
     
  4. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    The controls array is always accessible. If the action has not been enabled and bindings not been resolved yet, accessing InputAction.controls will trigger that. The contents of the array may change but whenever you access them, they will always reflect the currently resolved controls according to the configuration of the action.
     
    fstorehaug likes this.
  5. fredrik_unity363

    fredrik_unity363

    Joined:
    May 4, 2020
    Posts:
    3
    hey just wanted to confirm that this solved my problem! thank you!
     
    Rene-Damm likes this.