Hey OUYA Devs, as we are now done with our E3 stuff, I found some time to improve on the OuyaInput Framework that I was proposing in "Controller Solutions – (Con)Tribute to Tim".
This
new script is (I hope) a big leap forward to a simple to use, powerfull
and performance optimized cross-platform controller solution. I have decided to open up a new thread here to have a fresh start. Feel free to use this in your projects and please feedback about your experience with this approach. I am trying to improve it based on your comments. PLEASE read the documentation provided in this package. The stuff below can best be downloaded via right-click:
I've implemented it in my own game, but I'm having an issue when making a PC standalone version. It's not recognizing and switching to new controllers when I plug one in or out mid-game. Oddly enough, it works perfectly when I play in the editor. Any idea what might be causing that?
Hey, I need a few informations for checking this issue: 1. What type of controller are you using? 2. On which platform are you developing? 3. When you just put in the InputTester script in your scene, which controller name and type is printed on the GUI? 4. Are you using single or multiplayer.
I discovered one issue with the XBOX360 controller today. Somehow this controller seems to switch the player channel when unplugged and reconnected. This can be seen on the center button where the green quarter-ring indicating the player will shift.
When the player channel switches you won't get input for the player you call in your methods. Let's say you ask for player one's input and the controller suddenly decides to switch to player four...
Can you confirm this from your experience – or do we have another case? I thought this might be a driver issue. If this is the case we could develop a work around with OuyaInput dynamically switching the channels, giving back the correct player which then could be used via a variable to get the correct input.
I double checked, discovered some logic bugs and fixed them. As I have no controller here now I couldn't test the result now. I will do that tomorrow. However I would be intersted if this version works and solved your issues: OuyaInput_v0.02_alpha
I tried Tim's suggestion first and, sure enough, I found that the problem lies there, not necessarily with OuyaInput.cs. In the editor, plugging in and unplugging the controller works perfectly. On a standalone executable, it will react correctly when I unplug a controller, but it will never detect a controller that's plugged in while the game is running. Any suggestions for what I should try? If the problem is with Unity's Input class, I'm really not sure where to go.
EDIT: Actually, could someone else test this in a standalone Windows exported game? I wonder if this is a Unity-wide problem or just on my machine.
For the sake of compleness, here's the rest of my info:
- I'm using a wireless Xbox 360 controller
- On Windows
- InputTester shows the usual Xbox 360 wireless receiver string, but shows the same issue as detailed above (i.e. does not detect a hot-plugged controller)
- Testing with singleplayer for now
- I'm giving it plenty of time, way more than the requisite 3 seconds
- No, I'm not switching between types of controllers
The problem is buried on the level of the Unity engine. There is no way to solve it without tapping into the Unity source code. Unity's joystick recognition has some serious issues with hot-plugging which are discussed this Unity forum post I found:
OuyaInput.cs wraps access methods of Unity.Input (best performance and convenience). The only Unity.Input method to get to know the plugged controllers is: Unity.Input.GetControllerNames(). This returns a string array with the names that Unity considers to be joystick-ids. However on the lower engine level this method does not really poll joysticks reliably. This was discussed and also bug-reported to Unity but never fixed. So, as we can't accces the engine source for now, we have to live with two issues (I think this is mostly for the Wndows standalone player):
1. Hot-plugging will not always discover joysticks correctly (I hat no problem with hotplugging a PS3 on MacOSX, but hotplugging a XBOX360 USB on Windows did not work).
2. Sometimes (not often) Unity will mess up the joystick order. This means that ids in the array may not have the correct array index respective to the joystick axis channels. Mapping will mess up completely then. Again, no help.
Unfortunetaly this is as good as it gets. (Well, if someone writes a complete C++ joystick plugin to replace Unity.Input completely...there would be a chance).
Hah, I found this snipped in another forum:
Hi there
I've been bashing my head on the wall (well not literally, but still...) trying to figure this one out.
I finally worked it out so I thought I'd put the answer here to help anyone else who tries Googling for this.
I'm pretty sure it's a bug with the "Resolution Dialog" before your game runs. If you go to File -> Build Settings -> Player Settings -> PC, Mac & Linux Standalone and change "Display Resolution Dialog" to "Disabled" then even if you disconnect/reconnect the pad it should still work.
Might have answered my own question. I unchecked "Use Legacy Input" on the OuyaGameObject. No more error!
Yes, UNCHECK "Use Legacy Input" in our OuyaGameObject. This is absolutely vital – sorry I forgot to add this to the documentation (will do). Whenever you get these "UnityException: Input Axis "XX" is not setup."- errors, there are basically three mistakes I can think of:
1. You use the wrong InputManager.asset (sets Edit >> PrjoctSettings >> Input where you should now find about 100+ defined joystick axis with names like "Joystick1Axis1".
2.You indirectly call for an axis that is not defined anymore. That happens, when you use Legacy Input. I killed every axis setting that was only connected to legacy stuff and cleaned up. Legacy Input sometimes accesses axes via the wrapped Unity.Input.GetAxis() but doesn't know the new generic string ids of the respective axes channels.
3. You manually call Unity.Input.GetAxis() yourself. This should not be done. OuyaInput.GetAxis() wraps this method and adds some vital ids to do all the generic mapping and axis channel sorting.
Is it possible to use the "home" button on the ouya from within your class? I've been using it (fantastic piece of work by the way) but cannot find this anywhere in the documentation (or code for that matter). Am I missing something or is it just not possible with your class?
The OUYA Home Button is not really accessable and should not be. On the OUYA console it will allways bring you back to the main OUYA menu screen. This is part of the OUYA SDK and should always be left as it is. The button shows the same behaviour when using OuyaInput and porting to the OUYA.
That's what I meant with being part of the OUYA SDK. As this behaviour is very system specific and serves a specific function there, I was going for leaving it out of the cross.platform controller handler. It serves to fire Ouya specific events and is connected to the Ouya application lifecycle. Pretty much the same as the Android back or home capacitive buttons on tablets or smartphones.
Hm, I wonder wether this event listeners should find there way into the documentation. However I didn't get my hands dirty with these yet and do not really now what purpose they could serve in an Unity application – ANY TIPS?
Please Please Please gut the controller docs, I have been looking at stuff as i am about ready to setup my controllers and its confusing where there are multiple variants on how to do things. I think i know what to do and will find out when I get home tonight as I am unable to test while I am at work.
Also a huge Thanks to both Tim and Matthias. With out the work Tim has done and the additions from Matthias i would have a much bigger headache learning all of what would have to be done.
Just wanted to say thanks for this! Very nice and straightforward instructions, though I added OUYASDK-Core.unitypackage to my project first. Think that works better since there's less stuff to screw up.
Haven't tried an OUYA controller on PC, but 360 controller works on PC and console, and OUYA controller obviously works on the console too. Will let you know if I run into any problems.
This seems good enough to mention on the OUYA-Unity doc page (if it is, I missed it).
I like this controller library. So far, it's made life easier. However, how do I use it (properly) with other libraries? Specifically, NGUI. I managed to get the left/right wired up so I can select buttons in my GUI but I don't know what to use for joystick buttons.
Comments
GIT OuyaInputFramework
I would still recommend the standard download as I did some reformatting for GIT which looks better there but awfull in Mono Develop.
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
I need a few informations for checking this issue:
1. What type of controller are you using?
2. On which platform are you developing?
3. When you just put in the InputTester script in your scene, which controller name and type is printed on the GUI?
4. Are you using single or multiplayer.
I discovered one issue with the XBOX360 controller today. Somehow this controller seems to switch the player channel when unplugged and reconnected. This can be seen on the center button where the green quarter-ring indicating the player will shift.
When the player channel switches you won't get input for the player you call in your methods. Let's say you ask for player one's input and the controller suddenly decides to switch to player four...
Can you confirm this from your experience – or do we have another case?
I thought this might be a driver issue. If this is the case we could develop a work around with OuyaInput dynamically switching the channels, giving back the correct player which then could be used via a variable to get the correct input.
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
How much time do you let pass between the unplug and reconnect?
Are you switching controller types?
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
As I have no controller here now I couldn't test the result now.
I will do that tomorrow. However I would be intersted if this version works and solved your issues:
OuyaInput_v0.02_alpha
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
Relevant Unity Forum Discussion
OuyaInput.cs wraps access methods of Unity.Input (best performance and convenience). The only Unity.Input method to get to know the plugged controllers is: Unity.Input.GetControllerNames(). This returns a string array with the names that Unity considers to be joystick-ids. However on the lower engine level this method does not really poll joysticks reliably. This was discussed and also bug-reported to Unity but never fixed. So, as we can't accces the engine source for now, we have to live with two issues (I think this is mostly for the Wndows standalone player):
1. Hot-plugging will not always discover joysticks correctly (I hat no problem with hotplugging a PS3 on MacOSX, but hotplugging a XBOX360 USB on Windows did not work).
2. Sometimes (not often) Unity will mess up the joystick order. This means that ids in the array may not have the correct array index respective to the joystick axis channels. Mapping will mess up completely then. Again, no help.
Unfortunetaly this is as good as it gets. (Well, if someone writes a complete C++ joystick plugin to replace Unity.Input completely...there would be a chance).
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
Hi there
I've been bashing my head on the wall (well not literally, but still...) trying to figure this one out.
I finally worked it out so I thought I'd put the answer here to help anyone else who tries Googling for this.
I'm pretty sure it's a bug with the "Resolution Dialog" before your game runs. If you go to File -> Build Settings -> Player Settings -> PC, Mac & Linux Standalone and change "Display Resolution Dialog" to "Disabled" then even if you disconnect/reconnect the pad it should still work.
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
1. You use the wrong InputManager.asset (sets Edit >> PrjoctSettings >> Input where you should now find about 100+ defined joystick axis with names like "Joystick1Axis1".
2. You indirectly call for an axis that is not defined anymore. That happens, when you use Legacy Input. I killed every axis setting that was only connected to legacy stuff and cleaned up. Legacy Input sometimes accesses axes via the wrapped Unity.Input.GetAxis() but doesn't know the new generic string ids of the respective axes channels.
3. You manually call Unity.Input.GetAxis() yourself. This should not be done. OuyaInput.GetAxis() wraps this method and adds some vital ids to do all the generic mapping and axis channel sorting.
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
Updated all Links to OuyaInput Version_0.03.
Changelog:
– some minor bug fixes
– all console warnings fixed
– new utility access methods (GetJoystickAngle())
– updated documentation
– legacy input warning
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
Changelog:
– added support for Ouya Controller on Windows 8 (should also work on Win 7)
– updated documentation and package accordingly
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
On the OUYA console it will allways bring you back to the main OUYA menu screen.
This is part of the OUYA SDK and should always be left as it is.
The button shows the same behaviour when using OuyaInput and porting to the OUYA.
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
So better leave it to this event listener, right?
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
CLARK
by GoldenTricycle
Developer for CLARK / GoldenTricycle
Developer of OuyaInput Framework >> GIT
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
Haven't tried an OUYA controller on PC, but 360 controller works on PC and console, and OUYA controller obviously works on the console too. Will let you know if I run into any problems.
This seems good enough to mention on the OUYA-Unity doc page (if it is, I missed it).