Search Unity

InControl - input and cross platform controller support for Unity, made easy!

Discussion in 'Assets and Asset Store' started by pbhogan, Jul 18, 2014.

  1. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    513
    One more change needed for 2017.2 compatiblity

    KeyInfo.cs line 55, RuntimePlatform.OSXDashboardPlayer needs following change:
    Code (CSharp):
    1.                 if (Application.platform == RuntimePlatform.OSXEditor ||
    2.                     Application.platform == RuntimePlatform.OSXPlayer
    3. #if !UNITY_2017_2_OR_NEWER
    4.                     || Application.platform == RuntimePlatform.OSXDashboardPlayer
    5. #endif
    6. #if !UNITY_5_4_OR_NEWER
    7.                     || Application.platform == RuntimePlatform.OSXWebPlayer
    8. #endif
    9.                    )
     
    Carwashh likes this.
  2. FM-Productions

    FM-Productions

    Joined:
    May 1, 2017
    Posts:
    72
    Hi again!
    Thank you for your reply on my last question, it really helped a lot.

    Now I have 2 questions:
    1.) Is there a quick way to optimize performance for the InputManager update? It does take quite a lot of cpu time if there are many PlayerActionSets active at once. Or is there no easy way and I should try to edit parts of the source code to get more performance for the input update?

    2.) Is there a way to decouple the update for pulling for input from Unity's update function? I've read that Unity pulls the newest inputs from devices at the start of the Update function, but since you must have a lot of experience on how this works, could you give any insights on this topic? I would be great to decouple the functional update loop from the visual representation and I already have a similar system working. But I don't know how to deal with inputs more frequently than the Update() function is called. The reason I'm asking is that the game would feel much more responsive if I could for example process 120 inputs per second independent from the updates for the visual representation (Unity's Update())
     
  3. FrozenGun

    FrozenGun

    Joined:
    Oct 29, 2014
    Posts:
    9
    Hi PixelEnvision,

    thank you so much for sharing this, I had the same problems and they drove me a little bit crazy. I didn't search in the InControl code because of the latest update that stated support for 2017.x, so I gave InControl a pass.

    Now the input on iOS is working again, great!

    I saw your additional post for 2017.2, thanks for that, too.

    Best
    Andreas
     
    PixelEnvision likes this.
  4. BamBamAlicious

    BamBamAlicious

    Joined:
    Jan 29, 2017
    Posts:
    58
    Great work on this plugin! Just bought and using it and have had no trouble with controller mappings between different controllers and devices!

    However, I have come across a problem when building to my Android Phone (OnePlus 3, latest Oxygen OS at the time of writing) using a "Gen Game" controller.
    I've made a custom profile for the controller, and when using Unity Remote it recognises the custom profile perfectly, and controller works straight away, however on a build, I have to put the controller into mouse mode, then back to joystick before InControl begins to work. I've checked the console countless times and cannot seem to see why this behaviour is happening! Any help would be appreciated!

    EDIT: Nevermind! PixelEnvision's changes above have fixed the issue!
     
    Last edited: Nov 4, 2017
  5. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,561
    Is it possible to download an earlier version that works with unity 5.2.2? I bought InControl a while ago and am just getting around to it now, but the latest version only supports 5.5.5 and higher. I can send in my invoice number or whatever helps:) Thank you.
     
  6. SpreadcampShay

    SpreadcampShay

    Joined:
    Dec 9, 2010
    Posts:
    180
    Maybe this has been answered already, but what is the preferred way to check whether you are currently on Gamepad or Keyboard? I'd like to hide some UI Elements showing Controller Buttons if your last Input was a Keyboard instead of a Gamepad.
     
  7. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    http://www.gallantgames.com/pages/incontrol-bindings-faq
     
    SpreadcampShay likes this.
  8. SpreadcampShay

    SpreadcampShay

    Joined:
    Dec 9, 2010
    Posts:
    180
  9. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    I'm having an issue when the game is running at different framerates. When the game is running high framerate the camera look on the right stick moves very quickly but on different devices where the framerate is slower the look speed is much too slow. Is there a way to make it so that no matter the framerate the look will rotate at the same speed?

    Code (csharp):
    1.  
    2.  
    3.         public static TwoAxisInputControl Look
    4.         {
    5.             get { return InputManager.ActiveDevice.RightStick; }
    6.         }
    7.  
     
    Lars-Steenhoff likes this.
  10. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    That's not really an input issue. The input is always going to be in the range -1 .. +1 so most likely you need to multiply whatever value you're moving the camera by with Time.deltaTime, assuming you're doing it in Update().
     
  11. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Does anyone know which Joystick the Playstation controller is mapped to? Doesn't say anywhere in the documentation.
     
  12. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    A given controller is not mapped to any specific slot. It's just one of the devices in InputManager.Devices
     
  13. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,561
    I'm using unity on Mac. I have an instance of InControl in my scene with Use Native Input checked.

    If i use the TestInputManager sample script in my scene it works and i see the text showing me pressing various buttons, etc.

    I wrote this script and put it in the same scene, to try and register a button press but it doesn't work. When i press the buttons nothing gets sent to the console. Any idea what I am doing wrong?

    namespace InControl
    {
    using System;
    using System.Collections.Generic;
    using UnityEngine;

    public class BasicControl : MonoBehaviour
    {

    void Update()
    {

    if (InputManager.ActiveDevice.Action1.WasPressed)
    {
    Debug.Log("Button Pressed");
    }
    }
    }

    }
     
  14. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    @protopop I've replied to your e-mail on this.
     
  15. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    @pbhogan I have tested my changes for iCade on Apple TV if they affect iOS and they don't.
    So that means that you can safely support Apple TV and iOS with the same code for iCade.

    Code (CSharp):
    1.  
    2. #import "ICadeReaderView.h"
    3. #import <UIKit/UIKit.h>
    4. static const char *ON_STATES  = "wdxayhujikol"; //wdxazhujikol for German keyboard layout
    5. static const char *OFF_STATES = "eczqtrfnmpgv"; //ecyqtrfnmpgv for German keyboard layout
    6. @interface ICadeReaderView()
    7. - (void) willResignActive;
    8. - (void) didBecomeActive;
    9. @end
    10. @implementation ICadeReaderView
    11. @synthesize state = _state, delegate = _delegate, active;
    12. - (id) initWithFrame: (CGRect) frame
    13. {
    14.     self = [super initWithFrame: frame];
    15.     inputView = [[UIView alloc] initWithFrame: CGRectZero];
    16.     [[NSNotificationCenter defaultCenter]
    17.         addObserver: self
    18.         selector: @selector(willResignActive)
    19.         name:UIApplicationWillResignActiveNotification
    20.         object: nil
    21.     ];
    22.     [[NSNotificationCenter defaultCenter]
    23.         addObserver: self
    24.         selector: @selector(didBecomeActive)
    25.         name: UIApplicationDidBecomeActiveNotification
    26.         object: nil
    27.      ];
    28.     return self;
    29. }
    30. - (void) dealloc
    31. {
    32.     [[NSNotificationCenter defaultCenter]
    33.         removeObserver: self
    34.         name: UIApplicationWillResignActiveNotification
    35.         object: nil
    36.     ];
    37.     [[NSNotificationCenter defaultCenter]
    38.         removeObserver: self
    39.         name: UIApplicationDidBecomeActiveNotification
    40.         object: nil
    41.     ];
    42.     #if !__has_feature(objc_arc)
    43.     [super dealloc];
    44.     #endif
    45. }
    46. - (void) willResignActive
    47. {
    48.     if (self.active)
    49.     {
    50.         [self resignFirstResponder];
    51.     }
    52. }
    53. - (void) didBecomeActive
    54. {
    55.     if (self.active)
    56.     {
    57.         [self becomeFirstResponder];
    58.     }
    59. }
    60. - (BOOL) canBecomeFirstResponder
    61. {
    62.     return YES;
    63. }
    64. - (void)setActive:(BOOL)value {
    65.     if (active == value) {
    66.         if (value) {
    67.             [self resignFirstResponder];
    68.         } else {
    69.             return;
    70.         }
    71.     }
    72.     active = value;
    73.     if (active) {
    74.         if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
    75.             [self becomeFirstResponder];
    76.         }
    77.     } else {
    78.         [self resignFirstResponder];
    79.     }
    80. }
    81. - (UIView*) inputView {
    82.     return inputView;
    83. }
    84. - (void)setDelegate:(id<ICadeEventDelegate>)delegate {
    85.     _delegate = delegate;
    86.     if (!_delegate) return;
    87.     _delegateFlags.stateChanged = [_delegate respondsToSelector:@selector(stateChanged:)];
    88.     _delegateFlags.buttonDown = [_delegate respondsToSelector:@selector(buttonDown:)];
    89.     _delegateFlags.buttonUp = [_delegate respondsToSelector:@selector(buttonUp:)];
    90. }
    91. #pragma mark -
    92. #pragma mark UIKeyInput Protocol Methods
    93. - (BOOL)hasText {
    94.     return NO;
    95. }
    96. - (void)insertText:(NSString *)text {
    97.     // does not to work on tvOS, use keyCommands + keyPressed instead
    98. }
    99. - (void)deleteBackward {
    100.     // This space intentionally left blank to complete protocol
    101. }
    102. #pragma mark - keys
    103. - (NSArray * )keyCommands {
    104.     NSMutableArray *keys = [NSMutableArray array];
    105.     int numberOfStates = (int)(strlen(ON_STATES)+strlen(OFF_STATES));
    106.     char states[numberOfStates+1]; //+1 for crash on release
    107.     strcpy(states,ON_STATES);
    108.     strcat(states,OFF_STATES);
    109.     for (int i=0; i<numberOfStates; i++) {
    110.         UIKeyCommand *keyCommand = [UIKeyCommand keyCommandWithInput: [NSString stringWithFormat:@"%c" , states[i]] modifierFlags: 0 action: @selector(keyPressed:)];
    111.         [keys addObject:keyCommand];
    112.     }
    113.     return keys;
    114. }
    115. - (void)keyPressed:(UIKeyCommand *)keyCommand {
    116.     char ch = [keyCommand.input characterAtIndex:0];
    117.     char *p = strchr(ON_STATES, ch);
    118.     bool stateChanged = false;
    119.     if (p) {
    120.         long index = p-ON_STATES;
    121.         _state |= (1 << index);
    122.         stateChanged = true;
    123.         if (_delegateFlags.buttonDown) {
    124.             [_delegate buttonDown:(1 << index)];
    125.         }
    126.     } else {
    127.         p = strchr(OFF_STATES, ch);
    128.         if (p) {
    129.             long index = p-OFF_STATES;
    130.             _state &= ~(1 << index);
    131.             stateChanged = true;
    132.             if (_delegateFlags.buttonUp) {
    133.                 [_delegate buttonUp:(1 << index)];
    134.             }
    135.         }
    136.     }
    137.     if (stateChanged && _delegateFlags.stateChanged) {
    138.         [_delegate stateChanged:_state];
    139.     }
    140.     static int cycleResponder = 0;
    141.     if (++cycleResponder > 20) {
    142.         // necessary to clear a buffer that accumulates internally
    143.         cycleResponder = 0;
    144.         [self resignFirstResponder];
    145.         [self becomeFirstResponder];
    146.     }
    147. }
    148. @end
    149.  
     
  16. SamFZGames

    SamFZGames

    Joined:
    Mar 2, 2014
    Posts:
    52
    Hey guys, I have an odd problem on Mac. InControl works great for me, it detects my PS4 controller just great and maps everything appropriately. However my friend ran my game on his Mac with an Xbox One controller (using the usual driver), and the buttons hadn't remapped properly. He found that the buttons were all over the place, he was using the left bumper to pause (Command), right bumper to jump (A) and nothing else did anything.

    EDIT: I'm using Unity 5.6.5.

    EDIT AGAIN: I can fix this by checking "Enable Native Input", though that has me a tiny bit concerned since it's still in Beta.
     
    Last edited: Jan 13, 2018
  17. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,561
    I'm using Enable Native input for Mac . i leave it checked all the time and i read somewhere that it disables itself automatically on platforms that don't support it anyways. It makes my gamepad work on Mac and on Ipad it runs great too, so even though it says Beta it seems to be pretty mature. But its your call:)

    I didn't know there was a Unity 5.6.5! Cool.

    BTW unrelated but if it helps anyone, i also added a button in my options that inverts the Y axis in Incontrol itself. This was useful because i have an unsupported Nimbus controller that work sgreat on ipad and worked on MAc but the Y axis was reversed (for UI, joysticks, etc). At first i tried changing the InvertYAxis variable in the Incontrol Manager itself, but for that to take effect, i had to turn it on and off, which causes an error (see next post) because the InvertYAxis is set OnEnable. Then i found out i can set it ion the input manager directly using this code


    public void InvertYAxis (bool b) {

    InputManager.InvertYAxis = b;

    }

    Just make sure to add "using InControl;" at the top of the c# file (or "import InControl;" if it's Javascript
     
    Lars-Steenhoff likes this.
  18. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,561
    Is it possible to turn InControlManage on/off during runtime?

    I can disable it bu when i turn it back on i get a constant error : InvalidOperationException: Cannot be updated with an earlier tick.

    It's not essential, but for people not using a gamepad i though it would be good to disable it and stop the Update function running to save a bit of juice.

    BTW Loving InOCntrol - i played my game on iPAd last night , it even worked with the very old Steelseries gamepad.
     
  19. SamFZGames

    SamFZGames

    Joined:
    Mar 2, 2014
    Posts:
    52
    Indeed, the Beta does appear to be pretty mature, I've not had any issues with it at all so far. But I still feel concerned using something Beta in a commercial game. I'm hoping it'll be out of Beta by the time my game releases.

    Yessir! I would use 2018.1 but I'm keeping on low versions right now for safe porting to Nintendo Switch. Hopefully they should get that updated soon though.
     
  20. taihanh

    taihanh

    Joined:
    May 20, 2015
    Posts:
    1
    how defined button 20-21-22???
     

    Attached Files:

  21. Aston-Martin

    Aston-Martin

    Joined:
    Jul 5, 2012
    Posts:
    64
    hi,

    Enabled Xinput and working fine in editor, but no luck in getting rumble to work in UWP build.
    Mod XInputDevice.cs, XInputDeviceManager.cs with additional UWP platform depedent compilations.

    Would like to check, how to get Xinput fully working for window universal Il2CPP build on unity 5.6.5 ? (not able to use 2017/2018, due to too many technical obstacles to overcome)

    Br,
    Aston
     
  22. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    432
    Hi there !
    I read about the "InControlInputModule" but I can't get it to work in a "multiplayer" setting.
    How do you guys manage a commun "player selection screen" when Incontrol doesn't really change the fact that the Unity EventSystem is made for a "single" use ? :/
     
  23. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    UWP is not currently supported as it does not support XInput. UWP support will be added in the next update through Microsoft's Windows.Gaming.Input API, but you should be aware there is a bug in UWP where rumble doesn't always seem to work correctly with Xbox One controller and only one motor rumbles instead of two. Hopefully they will remedy that eventually. If you want to try the next version early, feel free to e-mail me and I'll get you a package.
     
  24. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    Yes, unfortunately this is a limitation of Unity's EventSystem. There's been open issues on the Unity UI project for quite some time on this and they haven't addressed it yet. Some devs have told me they deal with it as custom UI, essentially managing the navigation and selection logic themselves on those screens and only using Unity UI for layout.
     
  25. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    I'm removing the beta label on Native Input from the next release, actually (with no other changes to it). It's been rock solid in several released games on Steam, hasn't needed any changes or fixes in several months and even the last fixes were fairly minor edge cases. At this point, I'm confident it's more robust than Unity Input. Use it. :)
     
  26. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    Not out of the box. You'll probably need to make some modifications to InControlManager.cs to let you stop calling UpdateInternal(). You might actually be able to piggyback onto using InputManager.OnApplicationFocus() if SuspendInBackground is enabled, which essentially does the same thing.
     
    protopop likes this.
  27. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    432
    It sounds like a real bummer :(
    i mean, when we use a solution like InControl it means that most of us would have a REALLY hard time creating a whole UI Event System, doesn't it ?

    I can't believe that such a "usual" thing is not supported by Unity in the year 2018 ^^'

    Anyway, if someone around has already dealt with this problem I think a lot of people (including me :p) would really appreciate some help !
    Thanks, and keep up the good work :)
     
  28. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    Mentioned this to you on Twitter, but just for the benefit of everyone else, iCade on tvOS will be added in the next update.
     
    Lars-Steenhoff likes this.
  29. Aston-Martin

    Aston-Martin

    Joined:
    Jul 5, 2012
    Posts:
    64
    Yes, interested to get the vibration working for the controller, not too concern with left and right vibrate control.
    Can the update built with 5.6.5/D3D/IL2CPP/Net46 ? or does it need XAML ?
     
  30. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    It's just C# using the Windows.Gaming.Input framework, so it shouldn't need anything special.
     
  31. Aston-Martin

    Aston-Martin

    Joined:
    Jul 5, 2012
    Posts:
    64
    Ok, keen to test both L/R motors and L/R impulse triggers.
    Wondering if you implemented both ?
     
  32. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    If you cast InputDevice to UWPDevice there is a Vibrate method with four parameters.
     
  33. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,561
    Thanks - i ended up just leaving it disabled on startup so it only runs if there's a controller attached - and i figure by that point youll want to be using a controller for that game session anyways so it works out. Its all running great and its col to lay BrightRidge with the Gamepad, and it opens up some new options like using buttons to instantly access things that were hidden behind the menu before.
     
  34. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    @pbhogan
    Hi man,
    So I just bought InControl. I set up two scripts (the CharacterActions and CharacterController), following along with your bindings guide. I placed the InControlManager into the scene. I added the CharacterController Script, but am seeing nothing when I run.

    Any ideas?

    Also, from my stand point more tutorial videos/content would be awesome!


    edit,
    just to be clear I have two controllers (Logitech F310 and Xbox One [both USB]) working on my Mac. However, at run, the print to console shows no controller printed, as your tutorial did. ?


    EDIT: A button applying my Jump() is working, so " charActions.Jump.AddDefaultBinding (InputControlType.Action1);" but I can't find (InputControlType.DPadLeft); (InputControlType.DPadRight);
     
  35. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    I'm having trouble with a PS4 controller over bluetooth, same controller works perfect plugged into usb but when i connect it through bluetooth I'm not getting any input even though incontrol says:

    Joystick reconnected ("Wireless Controller").

    Do you have any idea what's causing the issue?
     
  36. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    If you are on Windows, it is most likely this known issue: http://www.gallantgames.com/pages/incontrol-known-issues#playstation-4-controller-on-windows
     
  37. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    Please e-mail me with more details. Do the controllers show up if you run the TestInputManager scene? What exactly are you expecting to "see"?

    Note, InControl does not necessarily print stuff in the console. That doesn't mean nothing is connected or working. Older versions may have been more verbose or had debug logging turned on.
     
    renman3000 likes this.
  38. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
  39. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    Do you see anything if you load up the TestInputManager scene? E-mail me with more details please.
     
  40. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    I sent you an email
     
  41. MetaMythril

    MetaMythril

    Joined:
    May 5, 2010
    Posts:
    150
    Hi @pbhogan

    I've been using InControl for a good while and must say it has been a lifesaver.

    Recently, I've been trying to figure out how to best swap two bindings when attempting to rebind an action at run-time that has an existing binding elsewhere.

    Use case:
    Action1 (Attack) bound to Binding1 (X Button)
    Action2 (Special Attack) bound to Binding2 (Y Button)
    Action3 (Dash) bound to Binding3 (B Button)

    Rebind Action1 to Binding2
    Action1 (Attack) would then be bound to Binding2 (Y Button)
    Action2 (Special Attack) would be forced to Binding1 (X Button) since it was previously mapped.

    I figure the best place to do this would be in ListeningOptions.OnBindingFound() or OnBindingAdded() but I'm going back and forth on how to make sure I'm not trying to force something to be done incorrectly.

    Is there a preferred way to handle this?
     
  42. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    There's no exact preferred way, but using those callbacks is what you want to do. The it's just a matter of figuring out exactly what you need to happen. OnBindingFound fires before the binding is actually added and gives you an opportunity to cancel or make adjustments first, which is probably what you want. OnBindingAdded only fires after all is said and done, but other rules (such as a binding limit) may prevent it from ever getting there.

    However, if all you're doing is providing a swap attack buttons option in your menu instead of a full custom bindings menu, then it may be easier to clear the bindings on each action and add the new bindings switched around.
     
  43. MetaMythril

    MetaMythril

    Joined:
    May 5, 2010
    Posts:
    150
    It's a full list of customizable bindings. So, just to make sure I accurately understand, if OnBindingFound fires when I'm listening for a binding, that means that InControl found an existing binding or that availability for binding is available? The "binding" argument when OnBindingFound was called didn't seem to have much info.

    I'm mostly trying to understand when/how I would find and store the existing binding (if it already exists elsewhere), release the binding from the selected action (this step optional?), apply the new binding to the selected action, then apply the stored binding to the action. Do I need to essentially loop through all of my defined actions and check for the relevant binding?

    Not sure why I'm having so much trouble wrapping my head around this. My goal is ultimately to setup a default control scheme then allow the user to swap bindings without causing something to become unmapped or mapped multiple times. Any insight you can give would be greatly appreciated.
     
  44. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    OnBindingFound is essentially saying InControl detected a control press while listening for a binding on an action and, unless you cancel it, the binding is about to be added to the action. It's giving you a chance to cancel adding the binding (by returning false), maybe cancel listening altogether (typically when ESC is pressed) or alter the existing bindings in some other way before doing so.

    I'm not entirely sure I understand exactly what you're trying to do. It sounds like a mixture of completely customizable bindings but then Attack and Special can be swapped under certain circumstances? Like, if you bind X to Attack, Y to Special, what happens when you bind A to Attack... does it just leave Y on Special? But if you bind Y to Attack it sees it's already on Special and assigns X (or whatever was on Attack) to Special? That's kind of odd behavior, but it can be done with some effort. I'm unsure why you even need this instead of just letting the player manage the bindings completely.

    Anyway, you should probably e-mail me more specifics so it can get off this thread and maybe I can give you more specific advice.
     
  45. MetaMythril

    MetaMythril

    Joined:
    May 5, 2010
    Posts:
    150
    Sorry for the late response. I pretty much figured out what I needed to do, though it presented me with an interesting question to ask.

    I have a default mapping profile that gets created when the system starts up, but default mappings show up as Action1, Action2, etc for the typical controller A, B, X, Y buttons. A remapping menu UI gets built around this time. When I go to remap buttons, the InControl figures out after initially loading that I'm now using a controller (OnActiveDeviceChanged gets fired when I press a controller button for the first time when starting) and the binding name goes from showing as Action4 to simply showing as Y when it gets remapped.

    I tried waiting to build the remapping window UI until OnActiveDeviceChanged is called, but the action binding names are still the nondescript Action1, Action2, etc. Is there a way for me to force binding names on actions to update once controller input is detected?
     
  46. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    You can't do that. InControl has no idea what the control is supposed to be called until there is an active device, and until something gives input, it can't guess what the active device might end up being.

    If you really don't like seeing Action1, then do a string replace on the name to replace it with what you want it to say. Of course, you might be wrong too... if you make it say X and you plug in a PS4 controller it won't be right until active device is switched and the proper names come in. Some controllers have X and Y switched, so it could be very confusing. But if it makes you happy, by all means make it say whatever you want.
     
  47. MetaMythril

    MetaMythril

    Joined:
    May 5, 2010
    Posts:
    150
    Sorry, there's a slight misunderstanding. I'm waiting until the device has been activated, but the menu was still getting built with the names as if the device wasn't already active. I found the solution was to wrap my building of the menu in a Coroutine so I can force a slight wait after the active device change has registered and that resolved the issue.

    EDIT: Perhaps the call to ActiveInputDeviceChanged() could be called after the input system as had a chance to update the bindings with the new active device? This would eliminate the need to wait to build the menu or do any other actions until the actions/bindings are in sync.
     
  48. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    Internally, the action set is updated right after the active device changes, so the callback happens before the action set gets a chance to update. I will look at delaying it until after the action set is updated, but that might be a bit onerous. Waiting a frame with a coroutine is a good way to handle it.
     
  49. Tycho_9000

    Tycho_9000

    Joined:
    Nov 12, 2013
    Posts:
    2
    Hi, I just started using InControl and am wondering how you call AddDefaultBinding when you want the default to be Input.GetAxis("Mouse X")? I'm trying to set up the camera following either the mouse or the left analogue stick, but it says it can't convert a bool to an InControl.BindingSource. Is there a certain way you're meant to set up mouse tracking in InControl? (Sorry if this has been asked before)
     
  50. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    384
    Take a look at Examples/Bindings/PlayerActions.cs, but it's done something like:

    playerActions.Up.AddDefaultBinding( Mouse.PositiveY );
    playerActions.Down.AddDefaultBinding( Mouse.NegativeY );
    playerActions.Left.AddDefaultBinding( Mouse.NegativeX );
    playerActions.Right.AddDefaultBinding( Mouse.PositiveX );