Search Unity

Rewired - Advanced Input for Unity

Discussion in 'Assets and Asset Store' started by guavaman, Sep 25, 2014.

  1. FeboGamedeveloper

    FeboGamedeveloper

    Joined:
    Feb 2, 2014
    Posts:
    47
    Hi, I would like to reset my value of input. For example I use an Axis that give value 1, is there one method that reset immediatly this value at 0? (like ResetInputAxes in Unity)
     
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    No. The value is determined by what the device itself returns. Resetting the value would cause a lot of problems depending on how the device returns values (events on change or continuous updating).

    There is very likely another solution to what you are trying to achieve. Please give me some information about what you want to do.
     
  3. FeboGamedeveloper

    FeboGamedeveloper

    Joined:
    Feb 2, 2014
    Posts:
    47
    I have one player that walk with input = player.GetAxis("Move Horizontal"). I would like to stop immediatly when i leave button (beacuse when I leave the button there are a some time to become 0)
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Zeroing input is absolutely not the right approach. Change the Digital Axis settings on the Input Behavior assigned to the "Move Horizontal" Action. Read about Digital Axis Simulation Settings here: http://guavaman.com/projects/rewired/docs/InputBehaviors.html

    Long story short:
    Set Digital Axis Sensitivity to 1000
    Digital Axis Gravity to 1000
     
    Last edited: Apr 29, 2015
  5. FeboGamedeveloper

    FeboGamedeveloper

    Joined:
    Feb 2, 2014
    Posts:
    47
    thanks, It works :D
     
  6. FeboGamedeveloper

    FeboGamedeveloper

    Joined:
    Feb 2, 2014
    Posts:
    47
    sorry, I have an other problem: I would like to leave the map keyboard when there is a joystick and vice versa, but when I put the keyboard map, don't works.

    This is my script:

    void OnControllerConnected(ControllerStatusChangedEventArgs args)
    {
    if (args.controllerId == 0)
    {
    ReInput.players.GetPlayer(0).controllers.maps.RemoveMap(ControllerType.Keyboard, 0, 0);
    }
    }

    void OnControllerDisconnected(ControllerStatusChangedEventArgs args)
    {
    if (args.controllerId == 0)
    {
    ReInput.players.GetPlayer(0).controllers.maps.LoadMap(ControllerType.Keyboard, 0, 0, 0);
    }
    }

    The line of ReInput.players.GetPlayer(0).controllers.maps.LoadMap(ControllerType.Keyboard, 0, 0, 0) don't work, not load the map!!! (yes, my map has layout 0, category 0 ed the controller id is 0).
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    This is wrong. controllerId is not an index, it's a unique id based on a counter. If you plug in a different type of controller or a second controller at the same time, this id will be different.

    Second, you don't know which player this controller is assigned to so you can remove the keyboard map. If you want to do this, you should either:

    1. Check which players have joysticks and remove the keyboard maps then based on who has a joystick.
    or 2. Assign the joysticks to players yourself.


    Again using a hard coded controller id of 0 will cause problems, and a hard coded player 0 won't work right if this is a multi-player game.

    player.controllers.maps.SetMapsEnabled(true, ControllerType.Keyboard, 0, 0);

    Maps always start disabled when added or loaded individually through scripting.
     
    Last edited: May 1, 2015
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Rewired 1.0.0.51 is live on the Unity Asset Store!

    1.0.0.51:
    API Changes:
    - Added AxisCalibration.sensitivity
    - Added AxisCalibrationData.sensitivity
    - Added Player.GetAnyButton
    - Added Player.GetAnyButtonDown
    - Added Player.GetAnyButtonUp
    - Added Player.GetAnyButtonPrev
    - Added Player.GetAnyNegativeButton
    - Added Player.GetAnyNegativeButtonDown
    - Added Player.GetAnyNegativeButtonUp
    - Added Player.GetAnyNegativeButtonPrev
    - Added ReInput.ControllerHelper.GetAnyButton
    - Added ReInput.ControllerHelper.GetAnyButtonDown
    - Added ReInput.ControllerHelper.GetAnyButtonUp
    - Added ReInput.ControllerHelper.GetAnyButtonPrev
    - Added Controller.GetAnyButton
    - Added Controller.GetAnyButtonDown
    - Added Controller.GetAnyButtonUp
    - Added Controller.GetAnyButtonPrev

    Bug Fixes:
    - Fixed issue causing joystick connect/disconnect events to fail if game window was detached in the Windows editor when Play mode was started when using native input sources.
     
    movra likes this.
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Important: Unity 5.0.1 has broken command line building in a major way. Do not use command line building if using Unity 5.0.1 at this time.
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Rewired 1.0.0.52 is available for download for registered users now on the website. If you've bought Rewired and want to get early access to the latest downloads, contact me with your email address. This update should be available on the Unity Asset Store in 5-10 days (based on current estimated approval times).

    1.0.0.52:
    Changes:
    - Removed dynamic platform DLL switching system due to bugs with no workarounds in Unity's command line batch building system.
    - Player.ControllerHelper.MapHelper.LoadMap now copies existing map.enabled state if loading over an existing map in the same category and layout.

    API Changes:
    - Added Player.ControllerHelper.MapHelper.LoadMap<T>(int controllerId, int categoryId, int layoutId, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.LoadMap<T>(int controllerId, string categoryName, string layoutName, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.LoadMap(ControllerType controllerType, int controllerId, int categoryId, int layoutId, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.LoadMap(ControllerType controllerType, int controllerId, string categoryName, string layoutName, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.AddMap<T>(int controllerId, ControllerMap map, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.AddMap(Controller controller, ControllerMap map, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.AddMap(ControllerType controllerType, int controllerId, ControllerMap map, bool startEnabled)
    - Deprecated Rewired.Editor.PlatformModeChanger.SyncToBuildTarget

    Bug Fixes:
    - Removed duplicate element identifiers in Thrustmaster T.Hotas Flight X controller definition.
    - Removal of dynamic platform DLL switching should eliminate all command line building issues.


    Command Line Building Issues Resolved for Good:
    After wasting huge amounts of time fighting with Unity's ever-changing and completely undocumented internal workings within command line batch mode building, I have decided to rip out the dynamic DLL swapping system in Rewired. Unity's batch building process is, as far as I am able to discern, incapable of updating and saving any kind of serialized data before the build takes place without intermittently resulting in either failing to include said data in the present build or even corrupting the serialized objects permanently. The internal workings of command line building seems to change with every release and all workarounds thus far have been very fragile and only work sporadically. Instead of continuing to play this game of cat and mouse, I've opted to remove the DLL swapping system so that now there is absolutely no processing on Rewired's part going on during a batch build anymore. The result of this is that all game builds will now include the libraries for all platforms, meaning game builds will now be from 150k to 1MB larger than before on all platforms.
     
    Last edited: May 3, 2015
  11. adamhill

    adamhill

    Joined:
    May 30, 2008
    Posts:
    26
    Could the 1.0.0.52 issues affect systems that might alter InputManager along with Rewired, being used in a project simultaneously? Specifically we are having issues with using the Oculus Gear VR camera (which mucks with the Input Manager) causing previously working Rewired code to completely quit working.

    The symptom is after we have setup Rewired to get it working, add the Oculus Camera Rig then we close the project and reopen it. And before the scripts want to recompile we get a dialog saying, it is overwriting a changed file (which is InputManager.asset) and if we do this we will lose changes. We get the 'Don't / Save' 'Save' dialog. We pick the save option, scripts recompile and no controls work anymore, but we can bring up the Rewired Input manager and see all of our Actions and Maps looking like they did before-hand.

    Any clue WTF is going on? Is Rewired fundamentally incompatible with other apps that directly manipulate InputManager or are various input systems supposed to exist in parallel, each talking to Unity's Input Manager?

    Anyone having success / failure with the GearVR Mobile SDK? We are pulling our hair out trying to figure out whats going on.

    Thanks for any help.
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    No, these changes have nothing to do with the InputManager.asset

    Obviously another script is rewriting the InputManager.asset file over and over. Rewired doesn't do this. It overwrites it only on install and only if you allow it to. This other script is behaving badly by just forcibly overwriting it with no user input.

    The issue here is Unity provides no way to access the InputManager settings through scripting -- that's the basis of all these problems. The only way developers have to access these settings is through directly manipulating the InputManager.asset file. Short of writing (or getting) a YAML parser (assuming the user has Force Text serialization mode set) to read the contents and add entries where you need them, the easiest way to add your own entries is to just replace it. Rewired does this, and apparently so does your other script that's causing these issues.

    There's nothing fundamentally incompatible with Rewired and something else that has Unity Input Manager entries. It's just that automated setup is backfiring in this instance.

    Here's what you do:
    1. Set asset serialization mode to Force Text in the editor settings.
    2. Install Rewired, let it overwrite the input settings.
    3. Copy the new InputManager.asset to another location.
    4. Let your other script run that overwrites Rewired's settings.
    5. Open that new InputManager.asset file in a text editor and the one Rewired made also.
    6. Merge the entries from the new inputmanager.asset file with Rewired's at the end, obviously following the YAML format and deleting any duplicate entries (like the default Unity axes). It shouldn't be difficult to do.

    I imagine after this your script will stop wiping the entries out because it can tell the ones it wants exist. Though how it's even checking for whether their entries exist, I don't know since there's no script access to this. If it's just doing a file compare or timestamp compare, then you're going to be out of luck because that would mean any changes to the InputManager settings are going to trigger a forced replace. If that's the case, that's some terrible programming there.
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Rewired 1.0.0.52 is live on the Unity Asset Store!

    1.0.0.52:
    Changes:
    - Removed dynamic platform DLL switching system due to bugs with no workarounds in Unity's command line batch building system.
    - Player.ControllerHelper.MapHelper.LoadMap now copies existing map.enabled state if loading over an existing map in the same category and layout.

    API Changes:
    - Added Player.ControllerHelper.MapHelper.LoadMap<T>(int controllerId, int categoryId, int layoutId, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.LoadMap<T>(int controllerId, string categoryName, string layoutName, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.LoadMap(ControllerType controllerType, int controllerId, int categoryId, int layoutId, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.LoadMap(ControllerType controllerType, int controllerId, string categoryName, string layoutName, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.AddMap<T>(int controllerId, ControllerMap map, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.AddMap(Controller controller, ControllerMap map, bool startEnabled)
    - Added Player.ControllerHelper.MapHelper.AddMap(ControllerType controllerType, int controllerId, ControllerMap map, bool startEnabled)
    - Deprecated Rewired.Editor.PlatformModeChanger.SyncToBuildTarget

    Bug Fixes:
    - Removed duplicate element identifiers in Thrustmaster T.Hotas Flight X controller definition.
    - Removal of dynamic platform DLL switching should eliminate all command line building issues.
     
  14. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Thanks for Thrustmaster T.Hotas Flight X controller definition (duplicate element fix).
     
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    NP! Thanks for bringing it to my attention.
     
  16. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Awesome asset Guava.

    Do you have an ETA on the uGUI examples that are mentioned in your documentation?

    Cheers!

    -Steven
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Mid June most likely. I am engaged in a time-sensitive contract project until the end of May. This post shows what I'm working on.
     
  18. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Sounds good thank you guavaman!
     
  19. timmehhhhhhh

    timmehhhhhhh

    Joined:
    Sep 10, 2013
    Posts:
    157
    How does one copy settings from one project to another? I assume this is something simple I'm missing, but at the moment am unable to find an answer. Loving this asset so far :)
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    http://guavaman.com/projects/rewired/docs/InputManager.html

    Make a prefab out of the Rewired Input Manager and copy that to your other project.
     
  21. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Hello! I been having a lot of success using Rewired, we recently decided to incorporate it into our existing project, all was working fine until I pushed to our git, now I encounter this non breaking error:

    This happens in all of the computers running the project. This also doesnt interrupt the plugin, it is working just fine, still we would like to get rid of the error if possible.

    Thanks.
     
  22. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    My guess is that the "Assets/Rewired/Internal/Data/EditorData/EditorPlatformData.asset" file isn't synced correctly via your git. Don't really know why, it's a rather simple YAML file. Might have something to do with the GUIDs it's using.

    Edit: Oh, just thought of a question regarding Rewired. Is it safe to move the Rewired folder to say Plugins (I know I have to move Editor folders to Plugins/Editor as well)?
    I like to keep my base folder as clean as possible to find things, and to minimize compile time. I've tried it long ago and it worked for a while (a delete then reimport fixed it). I am going to test it now and see if I encounter any issues :)
     
    Last edited: May 16, 2015
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Download the latest Rewired. EditorPlatformData doesn't even exist anymore since I pulled out the platform switching system. Please always check that you have the latest version before asking for support.

    Like Brainswitch said, your error is most likely caused by Unity regenerating the GUID of the file in each project you import it into. You must enable visible meta files if you're going to use version control or copy files from one project to another. This isn't a Rewired requirement, it's a Unity requirement because of how the Asset Database works. I have some explanation of it here in the docs of my other plugin.

    There shouldn't be any issues. Technically, when you put files in Plugins or a subfolder of it, it uses a different assembly -- Assembly-CSharp-firstpass and Assembly-CSharp-Editor-firstpass instead of Assembly-CSharp and Assembly-CSharp-Editor. This can cause problems with Reflection. But Rewired will try looking for its needed classes in both variations.

    That said, when updating Rewired, if new files are added to the distribution, they will create a new Rewired folder structure back in your Assets root. That's just how Unity's unitypackage format works and there is no workaround.
     
    Last edited: May 17, 2015
  24. knotFF

    knotFF

    Joined:
    Apr 13, 2013
    Posts:
    66
    Question for you.
    I have a few Map Categories like Menu, Walking, Driving, etc and I would like to have only one MapCategory on at all times, so let's say when I am on the Menu, only the categoryId 1 should be ON.
    I can turn all map categories off and then just turn the categoryId I want on, like so:
    Code (CSharp):
    1. playerRewired.controllers.maps.SetAllMapsEnabled(false);
    2. playerRewired.controllers.maps.SetMapsEnabled(true, "Menu");
    But what if I need to check whether the player is Walking or Driving before going to the Menu, so that when the player gets off the Menu it will return to the correct categoryId?
    I could not find a way to check which category/categories are on. Could you enlighten me on this issue?
    I am doing a Single Player game, so no need for multi-player input setup.
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    The most sensible way would be to simply track the game state in your code. When you change states (for example, you get in a car), store a record of the current state (Driving), then change the controller maps to match. Enter the menu, change the game state to Menu and then change the maps to match. When you exit the menu, you restore your previous state (Driving) and simply make Rewired sync with it. You shouldn't be trying to use the state of Rewired's maps to determine what your current game state is.

    Otherwise, to get the enabled state of a map, you iterate through the controller maps in Player and check the enabled property. You could then check the categoryId of each map itself to determine what categories are enabled or disabled.
     
    Last edited: May 16, 2015
  26. knotFF

    knotFF

    Joined:
    Apr 13, 2013
    Posts:
    66
    Thanks for the prompt reply. I was just searching for a work around, because some of the assets I am using are causing a bit of a problem with mouse look for example. But I guess you are correct, a status controller should be in charge.

    One more thing. When I run:
    Code (CSharp):
    1. playerRewired.controllers.maps.SetAllMapsEnabled(false);
    I will not turn off ALL the Map Categories in ALL Joystick/Keyboard/Mouse types, it only turns off (in my case) the categories in Keyboard.
    Is that how it's supposed to work? Shouldn't it turn all categories off in all controller types?

    Thanks.


     
  27. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Thanks Guavaman, I will do as you said.
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Yes, and it does. The source of the function shows no issues and a test I did shows no issues. It will only affect maps in that specific Player. How are you verifying these maps are not being enabled/disabled?
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Howso? Other plugins should not be able to influence Rewired's input settings in any way unless they modified the Unity InputManager, and this would only affect Rewired on non-native platforms or if you have native input disabled.
     
  30. knotFF

    knotFF

    Joined:
    Apr 13, 2013
    Posts:
    66
    Strange. I did some tests form scratch here. Did 3 categories and added them to Joystick and Keyboard.
    http://gyazo.com/194c34930bd039f88befd9a8aea11810
    http://gyazo.com/3d278885c8f8bb47d3b9de45a9454cd9

    playerRewired.controllers.maps.SetAllMapsEnabled(false);
    Only the keyboard buttons are turned off. The buttons on the Joystick continue to function normally.
    I also did this:
    playerRewired.controllers.maps.SetAllMapsEnabled(false, ControllerType.Joystick);
    and the Joystick buttons continue to function, but this:
    playerRewired.controllers.maps.SetAllMapsEnabled(false, ControllerType.Keyboard);
    Turns the keyboard buttons off with no problem.

     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Please email your project to the email address I will send you via PM. I've done the same test and do not get that result. Based on the source code of the functions, the result you're getting isn't possible.
     
  32. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    guavaman likes this.
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Following up for anyone reading:

    The key is that you are calling playerRewired.controllers.maps.SetAllMapsEnabled(false); in Start in an object that exists in your scene when Play mode is initialized. On OSX, the Joysticks are not reported by the OS instantaneously on initialization of the native I/O system, so you’re calling SetAllMapsEnabled before any joysticks have ever been reported to Rewired or assigned to Player 0. If you were to put a Debug.Log(ReInput.controllers.joystickCount) or Debug.Log(playerRewired.controllers.joystickCount) in before your SetAllMapsEnabled call, you’ll see zero. The joystick is then detected and assigned to Player 0 in a frame after your call and the maps are naturally enabled because of your settings in the Rewired Input Manager for that Joystick Map in that Player.

    Move your disable code out of Start and you’ll see it start working. There’s not really a reason you should ever have to call this on the very first frame of the game anyway. If you want to set the initial map states, just set them in the editor. You can also use the device attach event in ReInput to be informed when a controller is attached to the system.
     
    Last edited: May 20, 2015
  34. bkw

    bkw

    Joined:
    Sep 20, 2013
    Posts:
    49
    Is there a way to get a rewired joystick's Unity Joystick Id?
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    No. What would you need this for? If you're using native input on Windows, OSX, Windows Store, or Ouya, it won't even have a Unity joystick id.
     
  36. bkw

    bkw

    Joined:
    Sep 20, 2013
    Posts:
    49
    I'm trying to figure out how Rewired can be used on the Xbox One. Does it support hot-plugging / auto reassigning controllers? How do I vibrate the controller and it's triggers?
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    As far as I am aware, it will work on Xbox One to a degree. On this platform, it uses Unity input, not the included Xbox One input API, therefore all special features are unavailable. No vibration. Also, I've heard hot-plugging is poor on Xbox One without using the special API. You can try it and see. You will have to create a definition for the gamepad on the Xbox One platform though as it currently has no definition for that.

    I've attempted to get access to an XBone dev kit, but haven't heard back from Microsoft on this after talking with someone at the GDC. I'll have to keep pinging them and see if I can ever get one. Sorry.
     
  38. bkw

    bkw

    Joined:
    Sep 20, 2013
    Posts:
    49
    No worries. Thanks for the response. Rewired is already helping a lot on the PC side.

    Out of the box, my PC Rewired config seems to work ok on the Xbox One. Controllers are recognized, controller mappings work just fine. I'll have to test hot plugging. I can use their API to vibrate if I can get a hold of the unity joystick id.

    Thanks for creating Rewired btw.
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Okay, I just checked and see I do have an Xbox One definition for the controller. I forgot I added that. :oops: That's why it works out of the box.

    The main issue with hot-plugging will be controllers possibly getting crossed because they all have the same identifying name "Windows.Xbox.Input.Gamepad" (the name is the only possible thing you can match to on Unity input dependent platforms.) In the default auto-assignment config, Rewired will:

    1) Assign any available controllers to Players who have no joysticks assigned.
    2) When a controller is unplugged, the previous owner of that controller will be prioritized for the next controller attached, provided it matches.

    So in most cases, hot-plugging will work fine. The case where it won't is when more than one controller is unplugged simultaneously and then re-plugged (or disconnected wirelessly as it were). In that situation, Rewired will possibly give the controller to the wrong player.

    Really in such a case, without access to the Xbox One input API, there's no way to have perfect hot-plugging. Since you do have access, the best solution would be for you to just disable controller auto-assignment and assign them yourself. There are events you can use to tell when the controller is connected and disconnected. There are also methods in ReInput.controllers to assign a Unity joystick Id as the source for a controller. By you implementing your own assignment system, you would then always know the Unity joystick ID and be able to associate that to the correct Xbox One Input API ID and do your vibration, etc.

    Thanks! I'm glad it's been so useful to so many developers!
     
    Last edited: May 25, 2015
  40. Alima-Studios

    Alima-Studios

    Joined:
    Nov 12, 2014
    Posts:
    78
    guavaman likes this.
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Thanks for posting that! The game looks pretty cool! I'll have to download it and try it out. It's great to see what people are making with Rewired.

    As for the sfc30, I'll have to add that to the profile. Thanks for the tip!
     
  42. bkw

    bkw

    Joined:
    Sep 20, 2013
    Posts:
    49
    Will I still run into the issue of controllers being "mixed" after a disconnect? I recall in regular Unity input, if three controllers are plugged in, and one of them is disconnected, the other two could swap since you can't id which controller is which strictly by name. Does Rewired do anything to avoid this (even though its using Unity Input)?

    Also, I'm not sure how to manage my own unity joystick ids. When a controller is connected, it's automatically assigned a unity joystick id is it not? Then I override it? (with what?)
     
    Last edited: May 26, 2015
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Only if you choose for it to be:
    http://guavaman.com/projects/rewired/docs/RewiredEditor.html#Settings

    See "Joystick Auto Assignment."

    Controller Events:
    http://guavaman.com/projects/rewire..._Rewired_ReInput_ControllerConnectedEvent.htm
    http://guavaman.com/projects/rewire...wired_ReInput_ControllerDisconnectedEvent.htm
    http://guavaman.com/projects/rewire...ired_ReInput_ControllerPreDisconnectEvent.htm

    Assign Unity Joystick Id:
    http://guavaman.com/projects/rewire...Input_ControllerHelper_SetUnityJoystickId.htm

    Assigning Joysticks to Players:
    http://guavaman.com/projects/rewired/docs/HowTos.html#assigning-joysticks

    Assuming the Xbox Input API gives you some kind of way to get the Unity Joystick ID associated with a particular Xbox Input API ID:
    1. Disable joystick auto assignment
    2. Register for ControllerConnectedEvent
    3. Get the Xbox joystick ID for the Unity joystick ID
    4. Loop through the Rewired controllers and re-assign Unity IDs as necessary
    5. Assign the new controller to a Player
    If no such Xbox Input API function is available to associate a Unity joy id to the Xbox API id, then it's not possible.

    This is completely dependent on the platform. Unity's input system is really inconsistent. I have no way of knowing how the joystick ID's in are handled on the Xbox One. The only way to know is by testing. If you are able to associate the Unity id to the Xbox One API id, there should be no issues.

    The absolutely only piece of information Unity ever gives you about controllers is Input.GetJoystickNames. If the current platform keeps a fixed array length, then it's possible to prevent joystick crossing in all situations. If the platform collapses the array (Windows pre 4.6.3p1 / 5.0.0p1) or reorders all id's on connect/disconnect (OSX), it's completely impossible to prevent crossing 100% in the situation of multiple simultaneous disconnects. There is simply no way. (This is one of the fundamental flaws with Unity's input system that made it necessary to implement native input solutions like Raw Input and OSX I/O kit to give a proper joystick experience.) Rewired uses various techniques to try to match controllers back correctly, but this can only work 100% of the time on Unity Input fallback platforms if A) All joysticks in question have unique names or B) Only one joystick is unplugged and replugged at a time.
     
    Last edited: May 26, 2015
  44. bkw

    bkw

    Joined:
    Sep 20, 2013
    Posts:
    49
    Given a controller id and a controller type of joystick, how do I get the joystick id?
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    If you are looking for a way to get the underlying input source ID (like Unity joystick ID) you can't. The above solution I describe where you assign them yourself based on the Xbox One Input API id makes that unnecessary.
     
  46. bkw

    bkw

    Joined:
    Sep 20, 2013
    Posts:
    49
    Nope, I meant the joystick id of a Rewired Joystick. I want to call SetUnityJoystickId, which takes a joystick id.

    Right now, on ControllerConnectedEvent, if controller type is Joystick, I'm assuming that the controller id is equivalent to "joystick id" in the API. Is that correct?
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    http://guavaman.com/projects/rewired/docs/api-reference/html/F_Rewired_Controller_id.htm

    joystick.id

    But you probably also want to know this:
    http://guavaman.com/projects/rewired/docs/HowTos.html#get-controller

    Yes.
     
  48. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    Then, here you go. It's been released on Steam couple days ago.



    http://store.steampowered.com/app/365020/

    p.s. Do I understand correctly, that Rewired will soon provide a uGUI menu to rebind keys out of the box?
     
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,625
    Thanks for posting that! Good luck with the release!

    Yes, the uGUI menu was under development but had to be delayed a month due to another project. I am planning to resume work on it in about a week.
     
  50. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    Alright, i don t usually come on the forum to congratulate plugins, but this time, it is required.
    I am a noob programmer, trying to make it s first game. It's an FPS so i needed to have "remapping" for the players. I got Rewired few weeks ago, and only today decided it was time. Certain it would take a few hours for me to understand it all, i started at 8 Am. Followd the install procedure, jumped to the quick start page, set my few actions in it and jumped into my playercontroller.cs to figure it out.... 8.20 am , all done. I just can 't believe it. I am sure i am nopt using 90 % of what rewired has to offer, but.. it simply works. and now i can start making my "Remapping" option screen. Simply awesome.

    Thanks for this plugin, we need more quality plugs like that. Rewired just came in my "Default Plugin List" when creating a new project, alonside Alloy Shaders , SMAA , and A* Pathfinding.