Search Unity

[Released] cInput 2 - Unitys custom inputmanager got improved !

Discussion in 'Assets and Asset Store' started by Roidz99, Apr 4, 2012.

  1. SimonTBM

    SimonTBM

    Joined:
    May 10, 2013
    Posts:
    6
    Hello KeithT!

    I have been able to implement cInput into my project. I am using EZGUI, but a heavily modified version of it (had to write a whole bunch of stuff to support behaviours that are not native to EZGUI itself). I have hit a slight hurdle, but I have contacted the developers of cInput about it to resolve the issue (it is a trigger polling issue, nothing that will cause much grief I am hoping).

    But I do believe you will be able to implement cInput with relative ease. The documentation is very helpful and all in all, it has been super easy to get working with my own GUI. There are a number of functions that will make your life super easy and allow you to pull all the information you need to update text/UI and reset values etc.

    In short, I wouldn't be too concerned with making cInput play nice with NGUI, it provides enough easy to access functions for you to get all the information you will need to make it work with NGUI.

     
  2. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    Would you be interested on this cInput NGUI extension?







     
  3. SimonTBM

    SimonTBM

    Joined:
    May 10, 2013
    Posts:
    6
    Hey everybody,

    I am having a bit of a problem (I have contacted the developers but no reply yet so I just thought I would see if anybody here may have a solution). I am using my own GUI system with cInput 2 and have it working for the most part. I can map everything (keys, buttons and joysticks) as expected using the ChangeKey function, except for the triggers that have some strange behaviour.

    When you press a trigger to reset, it works fine. It changes the value for the target input and set scanning back to false. However, once you press another button to remap, it scans for one frame before it assigns the inverse to whatever the previous options was (EG: map Joy1 Axis 6+, the next will map Joy1 Axis 6-) without giving any input whatsoever. Once it has done this once, it will continue to behave normally and everything works fine.

    I was wondering if anybody had some across anything like this, or if anybody may be able to point me to a certain variable or function in cInput itself that may be causing it to set back to the inverse of whatever the input on the trigger initially was.

    Thank!
     
  4. KeithT

    KeithT

    Joined:
    Nov 23, 2011
    Posts:
    83
    @hjupter Yes would be interested to have a more detailed look.

    Have PM you contact details.

    Thanks

    Keith
     
  5. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    Look like modifiers are not working not even on the demo, anyone else have this working?
     
  6. mark-velthuis

    mark-velthuis

    Joined:
    Feb 10, 2011
    Posts:
    47
    I've got modifiers working for normal buttons, but not axis.
     
  7. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    I'm trying with the default demo (normal buttons) without any changes :/
     
  8. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
  9. mark-velthuis

    mark-velthuis

    Joined:
    Feb 10, 2011
    Posts:
    47
    I've tried it but it doesn't seem to work. I did have a few problems with modifiers but they went away when I placed cInput.cs in one of the gameobjects that are present at startup (except for the problem with axes, that one is still there). Maybe that's worth a try ?
     
  10. Kathrin-Jennifer

    Kathrin-Jennifer

    Joined:
    Mar 29, 2010
    Posts:
    128
    Hi,

    I have an issue with cInput in combination with Application.LoadLevel.

    I'm using a keyboard and a gamepad (see http://www.logitech.com/en-roeu/product/wireless-gamepad-f710) as input devices. After reloading the same scene some of the gamepad keys don't work anymore:
    * the dPad
    * the joysticks
    * LT
    * RT
    The gamepad is used in x-mode.

    All keys are used in different states for different interactions. The strange thing is that all of them work in some contexts but don't in others. allowDuplicates is set to true in my application.

    Any ideas how to get rid of this bug?

    Thanks a lot!

    Kathrin
     
  11. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    Oh wow ! a lot of new posts. I apoligize for not responding this week (or last week). I was on a 2 week vacation and i'm just back home.
    I will try to answer everyone's questions now one by one :)

    Glad this is solved :)
     
    Last edited: May 20, 2013
  12. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    I still cant get modifiers to work, I just imported cInput in a blank project, set the InpuManager.asset, opened the demo scene without changing nothing and still doesnt work :(
     
  13. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    1- Yes ! use the Keys class to make it easy for you, or type the corresponding strings (check the manual for the correct strings)
    2- We designed cInput to work with every GUI system. Several people allready used cInput with other gui solutions then the built-in one.
    If anyone want's to share their EZ-GUI or NGUI (or other solutions) to the cInput community, we would be honnered to put your solutions to our website for free downloads so everyone can benefit from it !
     
  14. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    I haven't used NGUI myself yet so i'm not sure how it works.
     
  15. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    First off, i think you forgot to add the Addmodifier functions (or you left them out in the pasted code)
    You add them like this: cInput.AddModifier(KeyCode.LeftAlt);

    Second, you are right, modifiers currently don't work with axis, only with getkey,getkeydown and getkeyup. We didn't really think that it should work with axis there modifiers are usually used for adding double or triple functions to certain keypresses. If you think this is wrong then let us know and we will try to implement this anyway in cInput.

    Then to you 2 suggestions/requests:
    point 1: we think this is a good suggestion and try to implement this in a future update !
    point 2: altough we discussed this internal a few times allready we have mixed feelings about doing this. Let me try to explain a little.

    We think that it's clear to the player which button to press because the GUI will display LeftAlt or RightAlt instead of just Alt. And getting the GUI to display just Alt presents its own complications. For example, we want developers to have the option to use LeftAlt and RightAlt (for example) for separate purposes in their projects, rather than requiring that either Left or Right Alt be interchangeable. So how would we allow a developer to decide which modifier keys (if any) to be interchangeable and get the GUI to display it correctly? It could be done, for sure, and we definitely see the benefit of having a combined keycode, but the way that modifiers are implemented in cInput makes us feel that frankly it would be quite a lot of complicated work for very little visible benefit, as we currently see it.
     
  16. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    We already discussed this via e-mail:

     
  17. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    There seem to be a problem with modifiers indeed. Secondary inputs won't react to the modifier keys. We will try to fix this asap.

    Modifiers do not work for an axis in cInput, and therefore the GUI menu won't accept modifiers for inputs that are used in an axis. The left, right, up and down inputs in the demo are used in axes, that's why the demo input menu won't accept modifiers for them.

    EDIT: we found the problem of secondary inputs not accepting modifiers ! we will submit a fix ASAP.
    If you need this fix faster then contact us !
     
    Last edited: May 20, 2013
  18. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    Do you think you can send us a small demo scene so we can test this ourself with a few controllers ?
    This sounds to be a weird bug and we would like to investigate this ?

    By the way, does this also happens when allowDuplicates is turned off ?
     
  19. Kathrin-Jennifer

    Kathrin-Jennifer

    Joined:
    Mar 29, 2010
    Posts:
    128
    Mh I'll try to create a demo with this bug. But since I don't know what this bug is caused by, I'm not sure if I'll manage to create a demo. I'll let you know asap.

    The bug also occurs with allowDuplicates turned off. Same behaviour.
     
  20. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    Kathrin-Jennifer,

    Can you give us a little more info about:
    - what did you put in your (cinput) setupscript (if possible paste the cInput setup code somewhere)
    - where did you put this setupscript
    - do you reload the scene where you put your setup script ?
     
  21. Kathrin-Jennifer

    Kathrin-Jennifer

    Joined:
    Mar 29, 2010
    Posts:
    128
    Got it! There is an object called "cObject" with the component "cInput" attached to the hierarchy of the scene. cInput is marked as "DontDestroyOnLoad". So when I restart my scene the "cObject" is in the scene twice.

    The problem is that I need to have to object in the scene, due to a bug with the execution order of Unity. I don't know yet how to refactor cInput in order to work with that. Most of the stuff is static...

    Edit: The cObject is now created, if it not already exist, by our SceneManager class which is the first to be initialized. Easy fix ;)
     
    Last edited: May 24, 2013
  22. V4nKw15h

    V4nKw15h

    Joined:
    Dec 16, 2011
    Posts:
    47
    I just bought cInput and installed it into my game. Firstly, thanks for a great product. It saved me countless hours. I did run into one problem though:

    So I want to allow the player to reassign the left mouse button. I've created a GUI system, and it uses the standard GUI.Button to reassign keys. So I left mouse click on the GUI.Button and ". . ." appears. Now I want to assign Mouse0 to that control. But when I click left mouse it instantly reverts back to ". . .".

    If I hold down left mouse while it's scanning, I see that the button changes to "Mouse0", so it is successfully assigned, but when I release the mouse button, this retriggers the original GUI.Button, causing it to think I want to assign a new key again, and returns instantly to ". . ."

    Obviously the cInput script registers the key I want to assign on MouseDown, and my GUI.Button registers on MouseUp. So they both fire one after the other causing an endless loop preventing me from assigning Mouse0 to a control.

    I know this is the case because if while ". . ." is visible, I hold down left mouse, and then move the mouse away from the button, it will not fire the GUI.Button again, and the Mouse0 will remain assigned as intended. This is not something I can expect my players to understand though.

    I've lost two hours trying to find workarounds, but how can I possibly avoid the GUI.Button triggering on MouseUp, immediately after cInput registers using MouseDown.

    Any help to get around this problem would be greatly appreciated. If cInput triggered keybind assignments on MouseUp, instead of MouseDown, this problem wouldn't be occuring.

    I'm amazed nobody else has run into this problem before so I'm sure some of you already found a workaround that is eluding me.
     
  23. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I just replied to your e-mail. But the solution we use is to implement a timer so that it records the time you click and ignores all future clicks until a short time has passed since the initial click. Take a look at _clickDelay in our cInputGUI.cs file to see how it's used.
     
  24. V4nKw15h

    V4nKw15h

    Joined:
    Dec 16, 2011
    Posts:
    47
    Okay thanks Deozaan. So I'm not going crazy then and this does need a little bit of extra code to get working. I'll take a look into the clickDelay solution that you use after the weekend.
     
  25. V4nKw15h

    V4nKw15h

    Joined:
    Dec 16, 2011
    Posts:
    47
    Well I implemented the clickDelay exactly as you do in your own GUI but this makes no difference to the problem. I'd already tried implementing a similar solution without success. It is occuring, I believe, due to the way onGUI runs multiple times per frame. I will try to find a solution to this problem but I wish cInput didn't scan for keyDown, and instead registered on keyUp, which would totally avoid the problem in the first place.

    Anyway, today I started testing out gamepad support and ran into another issue. Sorry :(
    So my game is a first person shooter. I use mouse for mouselook, and I have this set up without any issues. However when I add the right thumbstick for secondary controls for looking around, the mouse stops working and so does the thumbstick. However if I move both the mouse AND the assigned thumbstick at the same time, my character will look around.

    Edit: I believe this happens because I deal with sensitivity myself. Eg.
    pitch = cInput.GetAxisRaw("Pitch") * currentMouseSensitivity;
    So I believe that cInput is multiplying the zero movement from either the mouse or the thumbstick to cause a final movement of zero. It should only be zero if both mouse AND thumbstick are zero otherwise it should use whatever value is non-zero.

    So I decided to swap my code around to use cInputs built in sensitivity to bypass this, but cInput sensitivity does not seem to affect mouse movement. No matter what value I used, the sensitivity was always the same (even sensitivity 0).
    I needed to use GetAxisRaw because GetAxis was creating horrible mouse smoothing. Can you check that your sensitivity code applies to GetAxisRaw.
     
    Last edited: May 27, 2013
  26. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    I'm using SetKey on first load of my game to establish the defaults. The current key is "Test" and the default is Alpha1. The problem is when I call ChangeKey and change it to A it's not working. When I call GetText it's coming up as "Alpha1 + A". Any idea what's going on? Why is it storing the ChangeKey as a modifier or something of the sort? I'm calling ChangeKey directly as I have my own UI if that matters. The only workaround I can come up with is using Clear() then using SetKey to force the defaults to the keys the user supplied. I'm using the below to change the key exactly.

    Code (csharp):
    1.  
    2. cInput.ChangeKey( 'Test', 'A', 'None' );
    3.  
     
    Last edited: May 29, 2013
  27. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Can you show me what your setup script looks like that sets up these inputs? I think that would help figure out what this problem is.

    GetAxisRaw does not apply any sort of filtering to the axis. It just uses the raw value. I believe this is the normal (and desired) behavior for this function.

    I have verified this is a bug and it will be fixed in the next version. Sorry.
     
  28. V4nKw15h

    V4nKw15h

    Joined:
    Dec 16, 2011
    Posts:
    47
    It's fairly straightforward I think

    cInput.SetKey("Look Up", "Mouse Up", "Joy1 Axis 5-");
    cInput.SetKey("Look Down", "Mouse Down", "Joy1 Axis 5+");
    cInput.SetKey("Look Left", "Mouse Left", "Joy1 Axis 4-");
    cInput.SetKey("Look Right", "Mouse Right", "Joy1 Axis 4+");

    cInput.SetAxis("Yaw", "Look Up", "Look Down");
    cInput.SetAxis("Pitch" ,"Look Left", "Look Right");

    Then in my code to actuall rotate my character (it's a spaceship), I use:

    //Collect Mouse Movement here and rotate the ship
    pitch = cInput.GetAxisRaw("Pitch") * currentMouseSensitivity;
    yaw = cInput.GetAxisRaw("Yaw") * currentMouseSensitivity;
    roll = cInput.GetAxis("Roll")* rollSpeed * 25 * Time.deltaTime;
    hostTransform.Rotate(yaw, pitch, roll);

    This all works flawlessly with cInput if only the mouse is bound, but as soon as I add the secondary gamepad axis to the controls, the mouse stops working completely, and the gamepad thumbstick also doesn't work. However, like I said, if I move both the mouse AND the gamepad thumbstick, at the same time, in the same direction, my ship will look around. I haven't tested this, or looked at your code yet, but I'm assuming that it's multiplying the zero response from one of the axis into the returned result - hence I only get a reaction if BOTH primary and secondary are moving at the same time.

    I have promised my alpha testers a new build for this weekend, and it would be awesome if you could confirm this is a bug and sort a new build in the next couple of days. Or of course let me know what to tweak in either of our code to make this work.

    Incidentally, I believe this maybe only happens with the mouse and gamepad thumbstick combo. Using keys as primary controls, and gamepad thumbstick as secondary, for strafe up,down,left,right, works fine with no conflict. They are also using Axis'.

    Edit: Having thought about this some more, obviously the gamepad isn't going to work with my above code anyway. I can't alter the rotation of my ship directly with the gamepad input like I can with the mouse. So I'm going to have to rework the code anyway. I will add a toggle in my controls window "Use Gamepad To Look Around", and then swap the primary controls to the gamepad along with running different code for moving my ship. So don't worry. I will solve this one myself, but you may still want to look into this strange conflict anyway.
     
    Last edited: May 29, 2013
  29. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    Awesome, thank you!

    How do I use modifiers with ChangeKey? SetKey lets you set the primary and secondary key modifiers, but ChageKey does not. Do I simply send LeftShift + A and that'll give it a modifier of LeftShift?

    Update: Redid my usage and everything is working fine now. Seams to work better when you use the ChangeKey usage that waits for next input to be pressed.
     
    Last edited: May 29, 2013
  30. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I have confirmed this issue. I'll be looking into fixing it. Thanks for the detailed report. (c:

    As you said, ChangeKey does not allow you to pass in modifiers. That was something we overlooked when we implemented the modifiers feature. It will be fixed in the next version of cInput. Thanks for pointing it out.
     
  31. cdevl

    cdevl

    Joined:
    Apr 10, 2013
    Posts:
    180
    Searched forum for this - could not find an answer. So apologies if I missed it. I'm using the latest (free) version of Unity. Just bought CInput. After asset import the recompile gives me 8 errors in cInput.cs. They are all the same. Here is one of them.

    c:\AppsAndDocs\work\unity\rumble\Assets\Plugins\cMonkeys\cInput.cs(85,85): Error CS0241: Default parameter specifiers are not permitted (CS0241) (Assembly-CSharp-firstpass)

    I know Unity supports default parameters. So what am I missing?
     
  32. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    That error message doesn't make any sense to me. Looking at that line number and column (85, 85), the error seems to be saying it is occurring in the middle of a comment? I'd try reloading your project, and if that doesn't work, try deleting everything related to cInput and reimporting it all.
     
  33. cdevl

    cdevl

    Joined:
    Apr 10, 2013
    Posts:
    180
    Sorry. The line is actually 311. Reimported everything from the store again - restarted. The same result. Line 311 is:

    Code (csharp):
    1. private static void _SetKey(int _num, string _name, string _input1, string _input2 = "") {
    2.  
    and the error is pointing to the _input2 parameter.
     
  34. cdevl

    cdevl

    Joined:
    Apr 10, 2013
    Posts:
    180
    Also loaded from a totally empty project - the same result. Also tried it on a different pc - same result.In case it matters - using Unity 4.1.3f3
     
  35. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Are you coding with C# or UnityScript (JavaScript)?
     
  36. cdevl

    cdevl

    Joined:
    Apr 10, 2013
    Posts:
    180
  37. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I'm downloading Unity 4.1.3 now to see if it does the same thing for me.

    EDIT: I just imported the latest cInput package (2.5.3) into Unity 4.1.3 in a new project and I'm not getting the same error.

    Can you zip up your project and send it to me? I can't get duplicate this problem. . .
     
    Last edited: May 31, 2013
  38. cdevl

    cdevl

    Joined:
    Apr 10, 2013
    Posts:
    180
    Ok. How do you want me to send you the project? (size of the zip is ~10Mb)

    I also tried one more thing:

    1. On a third computer upgraded Unity to 4.1.3
    2. Created a brand new empty project - no additional packages imported - there is no code here that is mine
    3. Imported CInput
    4. Replaced Input Manager asset package (CInput menu)
    5. Opened C# demo scene from CInput - demo runs fine
    6. double clicked on one of CInput scripts to go to Monodeveloper
    7. in monodeveloper pressed F8
    8. got the same 8 errors
     
    Last edited: May 31, 2013
  39. cdevl

    cdevl

    Joined:
    Apr 10, 2013
    Posts:
    180
    For now I just removed these default parameters. The rest works. I was able to switch my project inputs to cInput. So far no other issues.

    Still would like to know why default parameters are causing a problem. :)
     
  40. V4nKw15h

    V4nKw15h

    Joined:
    Dec 16, 2011
    Posts:
    47
    Hey again Deozaan: I just wanted to let you know that I solved the mouse/thumbstick conflict in my own way. Because the mouse and thumbstick needed to use different code to alter how they move the ship in my game it actually made sense to put each on a different axis anyway so obviously the problem could no longer occur.

    So now I first check the mouse axis and allow it to turn my ship, and immediately afterwards I check the thumbstick axis. I didn't want to allow the player to mess up their game by rebinding the mouse axis anyway, so in hindsight this solution is actually better as it allows the player to rebind the thumbstick with no fear of them messing with the mouse.
     
  41. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    If you could e-mail it to cMonkeysSupport @ [my forum username] .com that would be great. Thank you.

    I don't use MonoDevelop. But I'm curious about what F8 does? I'll try it out myself once I've got your sample project.

    If I can't figure out what the problem is, I may just have to do the same thing you did and remove the default parameters. But you're the first person to report such a problem since cInput 2.x has been out (over a year now), so I have a hard time believing it's a problem with cInput itself.

    I'm glad you got it sorted. But I think the problem you reported still needs to be fixed, as I don't think it should work that way.
     
  42. cdevl

    cdevl

    Joined:
    Apr 10, 2013
    Posts:
    180
    Thank you. Will send my "empty" project later today. For what it's worth I also don't believe it is a problem with cInput. It has to be something with Monodevelop in the latest version.

    Note: F8 in Monodevelop just does a full rebuild of the solution.
     
  43. 3TechCorp

    3TechCorp

    Joined:
    May 4, 2013
    Posts:
    1
    forget about this. I made a mistake.
     
    Last edited: Jun 1, 2013
  44. mark-velthuis

    mark-velthuis

    Joined:
    Feb 10, 2011
    Posts:
    47
    Sorry for the late reaction, I've been away on vacation for a while and kinda forgot about this.
    I did indeed leave the "Addmodifier" part out of the pasted code. Modifiers themselves work fine for me with the exception of axes.

    I can think of a few reasons why you'd want modifiers to work with axes. One of the more common situations is seen in today's MMOs where WASD is commonly used for movement. But the A and D keys differ between rotating and strafing depending on wether you're holding the mouse look button or not. It's not realy that big a deal because it's easy to do yourself. I just thought I'd mention it because it wasn't in the documentation so I thought it might have been a bug.

    I completely understand the issue about point 2. I've experienced a game engine that didn't see a difference between left and right alt/shift/ctrl, and that was far more annoying than having to check for both of them. You did make the right choice if you ask me. I asked because the program I'm working on right now is aimed at a userbase that is known for not being very familiar with computers to the point where they might not understand the difference between left and right shift. ("They are both callled shift buttons. They both work the same in microsoft office") That kind. But again like the modifier keys with axes, it's pretty easy to work around.
     
  45. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
  46. lsgheero

    lsgheero

    Joined:
    Mar 24, 2013
    Posts:
    60
    Hey guys sent you an email via your site about this but read something in here about that possibly being broken despite it saying it sent the email.

    Awesome unity addon, however I seem to be having an issue adding my throttle/pedals as axis inputs or "keys". The system expects that everything is always at 0 when scanning which is not the case for my throttle (altho I can get that to behave it seems like that will be problematic for users) and the foot pedals are nearly impossible to keep at 0 since they are raised by default IE at -1. Because of this its autochoosing an axis on one of the pedals or the throttle. I can't even set normal keys because it wants to use the axis as a key input.

    Not sure if this is a bug or just something I am doing wrong, any assistance in appreciated.
     
  47. lsgheero

    lsgheero

    Joined:
    Mar 24, 2013
    Posts:
    60
    duplicated for some reason... :(
     
    Last edited: Jun 10, 2013
  48. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Hi lsgheero,

    As you know by now, we did receive your e-mail and have been trying to work with you to find a solution to this problem. But I just wanted to clarify that what was broken in the past was these Unity forums were not notifying us of replies to this thread, or PMs. But that has been fixed. So it's safe to contact us via e-mail or via this forum thread.

    Thanks.
     
  49. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Is there a simple way to check if a device input is currently bound to a cinput action? In this particular case I want to check if any actions have been bound to a mouse button.
     
  50. lsgheero

    lsgheero

    Joined:
    Mar 24, 2013
    Posts:
    60
    Yep! :) like I said awesome software.... hoping you can have the issue with the calibrate button resolved shortly!