Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Rewired - Advanced Input for Unity

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

  1. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    I would be interested in knowing if this is reproducible in a new project on your same machine with nothing but Rewired installed.

    One clunky workaround would be to set the inspector to Debug mode before clicking on the Touch Controller. You wouldn't be able to see the editors, but it wouldn't keep making new buttons. Disabling the foldout for the element creation buttons should also stop it since that code will not be executed if the foldout is open. In order to do this, you might have to go into Debug mode, disable the option to select newly created objects, then go back into normal mode, close the foldout, and delete the buttons it created.

    Thanks for the kind words. Supporting Unity and all the distribution platforms and operating systems involved as they constantly change has and continues to be a real challenge.
     
    Last edited: Dec 16, 2019
  2. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    47
    Hi there, probably a stupid question,
    I have an inputfield with ISelectHandler/IDeselecthandler methods implemented, they work fine using the old event system, however when I deactivate that and then activate my Rewired Event System, the .Select() method only works the first time I press the key I mapped for the method call. Am I missing something?

    I'm using Unity 2019.3.13f
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    I ISelectHandler.Select() only fires when a Selectable is first selected. This is used by the keyboard/joystick navigation system. When you move from one object to another, Deselect is fired on the previous and Select is fired on the next. It will also react to mouse clicks.

    Are you saying you're trying to repeatedly fire Select by hitting some key on the keyboard? This should not happen on Unity's StandaloneInputModule. Select is not Submit.
     
  4. ink13

    ink13

    Joined:
    Nov 14, 2013
    Posts:
    18
    Hi there,
    I, for the life of me, can't get the apple tv home button to be a button that can do an action 'in game', i'm trying to get the button to return the player to the main menu. Is there an example scene that demonstrates an apple controller.

    Or perhaps is there some debug scene where i can figure out what button maps to what?
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    https://docs.unity3d.com/Manual/tvOS.html
    a) Returning to the tvOS system home screen (if UnityEngine.Apple.TV.Remote.allowExitToHome is true)

    Set it to false.

    No. It works like every other controller. Create a Controller Map for it and assign the Actions to the buttons on the Controller Map.

    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information
     
  6. andrew210

    andrew210

    Joined:
    Apr 23, 2014
    Posts:
    172
    Originally I just tried to reimport Rewired from the asset store and ran through the install process again however after deleting the whole rewired folder and reimporting and running the install again, everything works perfectly again. Thanks for your reply and helping me stay on the right track toward a fix, your hard work is greatly appreciated.
     
    Last edited: Dec 19, 2019
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    I'm glad you found a resolution. Most likely, deleting the Extras/TouchControls and reinstalling them would have worked too if it was some case of corrupted serialized data.
     
  8. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    Input in multiple Fullscreen Windows in the backgroun in different screens

    Hello, it seems that in games running in the background, input with Rewired works just in Window or Maximized Window, but not in Fullscreen Window. I have 3 different games, each one running in the same PC but in a different screen. If the games are running in Window or Maximized Window everything works great using RawInput or DirectInput, but whenever I put any of them in Fullscreen, input just works if they are on focus. Any tips? Thank you.
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    All Raw Input devices are registered with Windows through the only API available to receive input messages. The only things that will stop messages from being received and/or processed are Unity's Run in Background settings (Rewired cannot update in the background if this is not enabled) and your Rewired Input Manager settings for ignoring input when the application is not in focus. Anything stopping input working beyond that is Windows itself not sending the input events to the window.
     
  10. narotuali

    narotuali

    Joined:
    Oct 23, 2018
    Posts:
    6
    error CS1615: Argument 1 may not be passed with the 'ref' keyword
    selectableCount = Selectable.AllSelectablesNoAlloc(ref s_reusableAllSelectables);
    i'm using unity 2019.2
     
  11. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    Thanks Guavaman, I will try to find a solution in Windows to prevent it for getting the input.
     
  12. narotuali

    narotuali

    Joined:
    Oct 23, 2018
    Posts:
    6
    #guavaman
    Your Documentation make me confuse
    i am using Rewired just to use the android Touch joystick so i only want to to get access to the horizontal and vertical (X&Y) of the Touch joystick by code i want A clear instruction or YouTube video
     
    Last edited: Dec 23, 2019
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    Download the latest version of Rewired.
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    I do not have tutorials on every single thing one could possibly choose to do in Rewired.

    If you are trying to use the system by getting values directly from code from components, you are going to have to look through the API reference yourself and figure out which functions to use to get the information you want. The entire API reference is documented.

    https://guavaman.com/projects/rewir..._ComponentControls_TouchJoystick_GetValue.htm
     
  15. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    How to make a single joystick control 2 mouse pointers

    Hello again guavaman, I'm using as example your demo PlayerMouseUnityUI and I manage to make 2 different joysticks control a different mouse pointer, but I would like to make a single Xbox Controller control 2 mouse pointers: one with left stick and another with right stick.

    How could it be made? I wonder if I need 2 different players and how to assign them the mouse actions being in the same joystick. I also read your doc https://guavaman.com/projects/rewired/docs/HowTos.html#assigning-controllers and I wonder if there's a simple way to assign a player a specific joystick with the Rewired Editor, or using their name instead of their GUID. How could I assign specific joystick with the same name (for example 2 Xbox Controllers)

    Thank you for your time and support
     
  16. narotuali

    narotuali

    Joined:
    Oct 23, 2018
    Posts:
    6
    that's not answer my question i bought Rewired to use joystick Touch on my mobile Game
    again i need to know how to use joystick Touch for Horizontal movement i need the code the example code not work with my player send me the code on how to connect the player with the joystick i need quick replay
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    You get input from Touch Controls the exact same way you get input from any other controller in Rewired. Create an Action, assign this Action to the Controller Map you created for the Touch Controller, and assign the Controller Map to the Player. Calling player.GetAxis("Action") will work exactly the same for a Touch Joystick as any other controller in Rewired. Your code does not have to care whether it's a touch joystick, gamepad, or keyboard.

    First, you must understand how to create Actions and set up input in Rewired:
    https://guavaman.com/projects/rewired/docs/QuickStart.html

    Rewired comes with tutorials on setting up input in general and on setting up Touch Controls:
    https://guavaman.com/projects/rewired/docs/TouchControls.html#custom-controller-setup
    https://guavaman.com/projects/rewired/docs/TouchControls.html#touch-controller-setup
    https://guavaman.com/projects/rewired/docs/TouchControls.html#touch-control-setup

    Rewired also comes with Touch examples for you to learn the system:
    https://guavaman.com/projects/rewired/docs/TouchControls.html#examples

    If you do not already know how to use Rewired and are trying to jump straight into using a Touch Controller, don't. You must learn the overall system first. read the documentation to learn the system. It is required in order to use Rewired.

    https://guavaman.com/projects/rewired/docs/
     
    Last edited: Dec 24, 2019
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    No. It is not that complicated.

    PlayerMouse:
    https://guavaman.com/projects/rewired/docs/PlayerControllers.html#player-mouse

    PlayerMouse requires you set up which Actions correspond to which elements on the mouse. The value of the Action is taken from the Player. It does not care what Controller or what element on that Controller the value originates from.

    Create two Player Mice.
    Create Actions for the left stick and the right stick.
    Assign the X/Y axes on one Player Mouse to use the Actions that you assigned to the left stick.
    Assign the X/Y axes on the other Player Mouse to use the Actions you assigned to the right stick.
     
  19. waqas_haxhmi

    waqas_haxhmi

    Joined:
    Jun 15, 2016
    Posts:
    11
    Hello guavaman!
    Hope you are doing well
    I bought your asset last year It was working fine for that scenario, actually it was great.
    But in my current game, I am having an issue like if 4 players are connected and 2 of them gets disconnect and I randomly connect them again then they both assign to different players.(e.x 3rd player connect to 4th and 4th connect to 3rd)
     
  20. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    Thanks guavaman. It works great. Btw, is there any solution for the other questions I made (I added 2 more):
    • I wonder if there's a simple way to assign a player a specific joystick with the Rewired Editor, or using their name instead of their GUID.
    • How could I assign a specific joystick while having 2 with the same name (for example 2 Xbox Controllers)?
    • How could I find the GUID of any joystick easily?
    • How could I differentiate 2 joystick detected as Gamepad or Unknown?
     
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    I need a whole lot more information than this to tell you anything:

    1. Unity version.
    2. Rewired version.
    3. Build target -- what platform are you doing this testing on?
    4. What controllers are you using for this testing and are they all the same type?
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    1. No. You do not assign joysticks in the Rewired Editor. Joysticks are either auto-assigned by the settings you choose in the editor or you have to assign them manually by code.

    https://guavaman.com/projects/rewired/docs/Controllers.html#joystick-assignment
    https://guavaman.com/projects/rewired/docs/HowTos.html#assigning-controllers

    2. You cannot know which joystick corresponds to a particular physical joystick without doing something to identify them like polling for input or vibrating the controller to tell the user which is which. That's why you must always provide a means for users to reassign joysticks.

    https://guavaman.com/projects/rewired/docs/BestPractices.html

    3. https://guavaman.com/projects/rewired/docs/HowTos.html#identifying-recognized-controllers

    4. That's multiple different questions. No joystick should be identified as "Gamepad" unless it's on a platform that only supports one type of gamepad. All joysticks can be differentiated by Joystick.hardwareTypeGuid as linked in #3. When multiple identical joysticks are attached, Joystick.id can be used to determine the specific Rewired joystick instance. This is not persistent. Joystick.deviceInstanceGuid MAY work to identify specific controllers across sessions but is not guaranteed to work on all platforms and input sources. The Unknown Controller type can only be determined through the Joystick.hardwareName string.
     
  23. danbg

    danbg

    Joined:
    May 1, 2017
    Posts:
    61
    Thanks guavaman. That's very helpful.
     
  24. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    149
    @guavaman, hi!
    Does Rewired allow vibration of game controllers in iOS and tvOS? We tried Sony DualShock 4 in iOS 13 and tvOS 13 and, unfortunately, had no vibrations.
    We're using Rewired 1.1.25.1.U2018, Unity 2018.4.12

    UPD. Joystick.supportsVibration returns false
     
    Last edited: Dec 27, 2019
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    No. Refer to the FAQ:
    https://guavaman.com/projects/rewired/docs/FAQ.html#force-feedback

    Vibration on iOS would require a native library. See the list of platforms that use native libraries:
    https://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms
     
  26. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    149
  27. CurryKitten

    CurryKitten

    Joined:
    Dec 22, 2016
    Posts:
    13
    Howdy. I just got the full version of Rewired today and started going through the docs/getting started and looking at the examples. I've hit an early bit of confusion which seems so simple and fundamental that I just must have missed something obvious - but rather than stare at the screen and potentially go round in circles, I thought it might be faster just to post here.

    As per the quick start docs, I went into the rewired input manager, added a player, joystick maps for the gamepad template and Unknown controller, assigned the map to the player - and left it in it's default way of auto assigning. Next I wrote some really basic code just to check that if I move the joystick around this is picked up (I'm just using the inspector to look at the values) The code is -

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Rewired;
    5.  
    6. public class MoveController : MonoBehaviour
    7. {
    8.     // The Rewired player id of this character
    9.     public int playerId = 0;
    10.     private Player player; // The Rewired Player
    11.     public float rollInput;
    12.     public float pitchInput;
    13.     public float throttleInput;
    14.     public float yawInput;
    15.  
    16.     void Awake()
    17.     {
    18.         // Get the Rewired Player object for this player and keep it for the duration of the character's lifetime
    19.         player = ReInput.players.GetPlayer(playerId);
    20.  
    21.         Debug.Log("Joystick count: " + player.controllers.joystickCount);
    22.         if (player.controllers.joystickCount !=0 )
    23.         {
    24.             Debug.Log("Joystick: " + player.controllers.Joysticks[0].name);
    25.         }
    26.     }
    27.     // Start is called before the first frame update
    28.     void Start()
    29.     {
    30.  
    31.     }
    32.  
    33.     // Update is called once per frame
    34.     void Update()
    35.     {
    36.         GetInput();
    37.     }
    38.  
    39.     private void GetInput()
    40.     {
    41.         rollInput = player.GetAxis("Roll");
    42.         pitchInput = player.GetAxis("Pitch");
    43.         throttleInput = player.GetAxis("Throttle");
    44.         yawInput = player.GetAxis("Yaw");
    45.     }
    46.  
    47. }
    48.  
    This was actually fine in running it, you can see the 4 axis pick up input and I'm able to swap between a PS4 controller (as a gamepad template) and an RC radio (as an unknown joystick) and it works perfectly.

    My confusion here is drilling down into the player class. Obviously I have a joystick and it's being correctly assigned as I can get input from it, but my bit of debug.log tells me that my total number of joysticks is 0, and thus I can't get it's name. I wanted to build from here and look at reassigning axis and doing calibration but this has stumped me a bit.

    More confusingly if I look at the debug version in the inspector for the rewired input manager I can see the player class exactly how I'd expect to see it

    https://imgur.com/0Ie1uUv
    (Edit: can't seem to insert an image - here's the direct URL showing the inspector window)

    Where am I going wrong here ?
     
  28. CurryKitten

    CurryKitten

    Joined:
    Dec 22, 2016
    Posts:
    13
    Ok, so it's a timing thing then ? I figured that starting up the program with a joystick already connected would mean that Rewired would start up with a joystick connected, but (after running the debug in the Update() loop) it seems to take around 2 frames before it notices that a joystick is connected.

    So I guess this is why subscribing to joystick connection/disconnection events is important? I stuck in a teeny bit of extra code to say

    Code (CSharp):
    1. ReInput.ControllerConnectedEvent += OnControllerChanged;
    2.         ReInput.ControllerDisconnectedEvent += OnControllerChanged;
    3.  
    4. private void OnControllerChanged(ControllerStatusChangedEventArgs args)
    5.     {
    6.         Debug.Log("Controller Changed");
    7.         Debug.Log("Joystick count: " + player.controllers.joystickCount);
    8.         if (player.controllers.joystickCount != 0)
    9.         {
    10.             Debug.Log("Joystick: " + player.controllers.Joysticks[0].name);
    11.         }
    12.     }
    So then I can see joysticks being unplugged/plugged in as I run. I take it this is the right way of doing so - as opposed to perhaps waiting to Rewired to tell me it's all ready to go or something similar ?
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    This is documented here:
    https://guavaman.com/projects/rewired/docs/HowTos.html#connect-disconnect-events

    Note: Joysticks are not guaranteed to be available on Awake or Start on all platforms or input sources. If Joysticks are available immediately to Rewired on Awake, Joystick connected events will not be sent (technically, they will, but you cannot subscribe to Rewired's events before it initializes because of Rewired's script execution order, so you can't react to these events). If Joystick availability is delayed, a Controller connected event will be sent when Rewired detects the controller. If you need to check for the presence of Joysticks at the beginning of your game, you should check in both Awake or Start and by subscribing to the ReInput.ControllerConnectedEvent or enable deferred controller connected events. The "Defer Controller Connected Events On Start" option in Rewired Editor -> Settings will defer controller connected events for controllers already connected when Rewired initializes until the Start event so that you can subscribe to the ReInput.ControllerConnectedEvent in Awake and react to the events.
     
  30. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    128
    Hey @guavaman.

    I am using ReInput.controllers.JoysticksGetAnyButtonDown() to find a controller with a button held and then Rewired.Player.controllers.AddController(joystick, true) to assign the joystick to the player and then using Rewired.Player.GetAnyButton() the same frame and its coming back as false.

    Is there a certain amount of time I need to wait before the assigned joystick is ready to be tested? Is there a function that will tell be that the controller is ready to be used?
     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    Rewired calculates Player Action once per frame at the beginning of the update loop before any of your scripts run. Player Action values cannot be re-calculated mid frame. You assigning a controller to a Player will have no impact on its Action values in that frame. The next frame it will be calculated.
     
  32. DevelopGamer

    DevelopGamer

    Joined:
    Nov 22, 2014
    Posts:
    24
    Hi guys,

    Happy New year and thanks to Guavaman for a really excellent asset. Not sure where we'd be without this!

    I've got both an Xbox one and a Glap controller set up already in less than 24 hours on my android game.

    I do however have a slight problem.

    When rotating the camera with the right hand stick, I'm using the default GetAxis approach. When I play in the editor this works flawlessly but I've noticed that on the mobile build sometimes the axis get locked and keeps rotating on the horizontal (left/right),even after I've released the stick. It seems to happen when multiple other buttons are pressed.

    So I was wondering could this be an android problem with lack of support for multiple button presses? Or is there a known solution to this kind of issue?
    Once again I hope you have a great year, and I'd appreciate any help you can give.
     
  33. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    Thanks and Happy New Year to you also!

    You would have to view the value of the Action at runtime in order to be sure this isn't something in your code causing it:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information

    If the value of the Action is showing the stick stuck on, then it is most likely either a problem with the controller or Unity. Rewired uses UnityEngine.Input for the source of all input on Android:
    https://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms

    You can use Debug Information to view the live values of the stick in the Controller (not the Action). If that looks wrong, look at the raw values coming from Unity using the low-level debug tool scene in Rewired/DevTools/JoystickElementIdentifier and see what values Unity is returning. If Unity is returning a non-zero value for the stick in these cases, there is no possible fix.
     
  34. DevelopGamer

    DevelopGamer

    Joined:
    Nov 22, 2014
    Posts:
    24
    Hi Guavaman, thanks very much for your quick reply and again for this excellent asset.

    I notice there's no GexAxisUp or OnReleaseAxis etc, I suppose that's inherently not how axis input works? It did occur to me that this could be a good failsafe.

    As above I'll log the actions based on that example you posted and will report my findings. If anyone else has experienced this issue I'd appreciate any additional insight into why this might be occurring.

    I have a number of other issues to attend to many of which are network related so I'll update asap.

    One final question is are there any more examples other than the introductory tutorial on handling camera movement with a right hand analogue stick? I noticed you are normalizing the input in the tilt demo, not sure if that's relevant to my issue. Furthermore I still have not really looked at the GamepadTemplate in much detail so I wonder if that demonstrates multiple buttons being pressed simultaneously, if so I could try building thst for android and see if I get the same issue.

    Hopefully my issue is simply a case of some other input code conflicting with rewired somewhere, but as I say I'll keep looking into it and report back when I can.
     
  35. IceBeamGames

    IceBeamGames

    Joined:
    Feb 9, 2014
    Posts:
    128
    That doesn't seem to be happening for me. I have to wait until end of frame twice before the GetAnyButton() registers. Should that not be happening then?
     
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    1. Waiting until end of frame once will do nothing. Rewired will not have calculated Actions again by that time.
    2. Waiting until end of frame twice will work but is unnecessary. Rewired already calculated the value at the beginning of the frame.

    There is no way possible Rewired would be calculating the value at the end of the frame after your scripts have already run. That's not how the system it written. It never calculates any Action values at any time except on the main update loop callback (Update, Fixed Update, OnGUI based on your settings) before your scripts run -- Script Execution Order -32000.

    Skip the frame with yield return null if you're using a coroutine. The value will be calculated by then (the start of the next frame).
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_InputActionEventType.htm

    AxisActiveOrJustInactive - Event fires every frame the axis value is non-zero and once more when the axis returns to zero.

    AxisRawActiveOrJustInactive - Event fires every frame the raw axis value is non-zero and once more when the axis returns to zero.

    There is no "GetAxisUp" polling function. You check the GetAxis value and if it is 0, there is no input.

    No. Rewired doesn't provide examples on character controllers, camera controllers, or any other input consumption processes that happen outside Rewired. Rewired doesn't provide tutorials on consuming input. There are literally infinite ways you may choose to consume input. Any scripts that were written for Unity will also work with Rewired with minimal changes. The source of the input values is irrelevant. Input processing and consumption is outside the responsibility of Rewired and I do not have the resources to make an exhaustive library of game development tutorials that extend beyond the functionality of the asset like Unity does.

    Input from joystick axes is automatically normalized to a -1 +1 range. The only thing you need to do to joystick axis values is multiply them by Time.deltaTime. See this for handling mouse and joystick axis values.

    There is nothing in Rewired that would prevent multiple buttons from being pressed and sticks moved simultaneously.
     
    Last edited: Jan 2, 2020
  38. CurryKitten

    CurryKitten

    Joined:
    Dec 22, 2016
    Posts:
    13
    Hello again,

    I'm using the InputMapper and I'm finding myself getting into situations I don't want, but I can't see an obvious (easy0 way around it. I'm wondering if I may have missed a "best practice" idea of how to manage my actionElementMaps.

    The problem I have is accounting for the possibility of new axis being used as controls. An example here using a PS4 joystick, where the two analog sticks are set to Pitch/Roll and Throttle/Yaw. So my maps would look like (slightly cut down to save space) -

    Code (Boo):
    1. Axis Maps(4)
    2.   0: Right Stick Y (Pitch)
    3.       id (unique id)                       32
    4.       Element Type                       Axis
    5.       Action id                              0 (Pitch)
    6.   1: Right Sitck X (Roll)
    7.       id (unique id)                       33
    8.       Element Type                       Axis
    9.       Action id                              1 (Roll)
    10.   2: Left Sitck Y (Throttle)
    11.       id (unique id)                       34
    12.       Element Type                       Axis
    13.       Action id                              2 (Throttle)
    14.   3: Left Sitck x (Yaw)
    15.       id (unique id)                       35
    16.       Element Type                       Axis
    17.       Action id                              3 (Yaw)
    18.  
    So all is good if I find all the actionElementMaps and ask the user to push a stick for each of the actions. The problem arises if someone wants to use a new axis of movement (this would be pretty unlikely on a ps4 controller, but I'm working with RC radios where each RC channel could be an axis - so potentially we could detect movement on one of 16 axis)

    When this happens I'd get a brand new actionElementMap with a duplicate action - so in the PS4 controller case, if someone pressed the L2 button we might get something like

    Code (Boo):
    1.  
    2. 4: L2 (Yaw)
    3.       id (unique id)                       36
    4.       Element Type                       Axis
    5.       Action id                              3 (Yaw)
    6.  
    Within my InputMapper.Context() I've got actionElementMapToReplace=null I did this because if I set it to the actionElementMap to replace, the map that I want to use instead is removed. So in the first example if I wanted to switch the pitch and roll sticks around I'd prompt the user to move the pitch stick, and they'd move Right stick X (currently mapped to roll) This would result in getting this map -

    Code (Boo):
    1. Axis Maps(4)
    2.   0: Right Stick X (Pitch)
    3.       id (unique id)                       32
    4.       Element Type                       Axis
    5.       Action id                              0 (Pitch)
    6.   1: Left Stick Y (Throttle)
    7.       id (unique id)                       34
    8.       Element Type                       Axis
    9.       Action id                              2 (Throttle)
    10.   2: Left Sitck x (Yaw)
    11.       id (unique id)                       35
    12.       Element Type                       Axis
    13.       Action id                              3 (Yaw)
    14.  
    ... and because the actionElementMap for Roll has gone, this never gets passed into the input mapper. Essentially what I'd like to do when doing a remap is to throw away all the existing maps and create new ones with the correct action id's.
    My problem with having duplicate axis with the same aciton is when I calibrate I don't want to have to guess which axis is actually being used, but I also can't risk going through after a remap and delete any duplicate maps to the same action in case the user has made a mistake and used the same axis twice and wants to go back and remap again.

    What should I be doing under these circumstance ?
     
  39. CurryKitten

    CurryKitten

    Joined:
    Dec 22, 2016
    Posts:
    13
    I really should post here more often... whenever I do I manage to figure out some workaround - but I thought I would describe what I'm doing here to check if this is considered the "right" thing to do. It's working for me at least.

    So when I do a remap I first do a controllerMap.ClearElementMaps() to remove all the existing maps. I then enter into a loop that goes through my 4 Actions. Before starting the input mapper I use a controllerMap.CreateElementMap to create a new element map with my action id and in the options set this elementmap as the one to replace.

    This results in a whole new set of maps being created everytime we do a remap (but we remap all controls in this anyway) and it doesn't matter if new axis are introduced... this then results in the calibration working fine as there are no duplicate actions.
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    @CurryKitten

    There is nothing illegal about having multiple elements mapped to the same Action. If you don't want to allow this in your game, you should design your remapping UI in a way to prevent this from happening. Rewired's Control Mapper limits you to X number of mappings per Action and only display X number of mapping fields per Action (developer-defined) to enforce this. Your UI design will dictate how this works. I can't give you any "best practice" advice here. You are free to use the mapping system however you like. If you choose to limit your users to 1 element per Action, that's up to you. If you want that, have it replace the existing mapping when they assign a new one to that Action.

    If the user wants to replace a mapping, you pass the ActionElementMap to replace. If you're trying to force them into having only one mapping per Action, this is the way to do it.

    Why would this cause a problem with calibration? Calibration is inherently per-device, per-axis. Calibration has nothing to do with Actions. Calibration applies to the axes on the device before any Action values are calculated. Your user should be allowed to calibrate each axis individually on the device to account for worn devices or odd devices. This is shown in both the ControlRemapping1 examples and Control Mapper.
     
    Last edited: Jan 5, 2020
  41. mdsitton

    mdsitton

    Joined:
    Jan 27, 2018
    Posts:
    36
    @guavaman Hello question, for our game we would like to support xbox one rock band 4 instruments from madcatz and PDP, but they do not show up as raw input or xinput devices under rewired. Is there anything we can do here?

    here is the hid and vender id and other info from the device for the guitar from the device manager.

    Thanks,
    Matthew
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    No. Devices that do not show up as Raw Input/Direct Input or XInput devices cannot be used.
     
  43. virgiliu

    virgiliu

    Joined:
    Apr 4, 2015
    Posts:
    42
    Hi. Is there a way to simulate player input from code? I'm trying to create an AI player and I would prefer having the AI make use of Rewired instead of hooking it directly into the player controller. Is this something possible with Rewired?

    Edit: It seems like a custom controller (https://guavaman.com/projects/rewired/docs/CustomControllers.html) might be the answer but I have to double check.
     
    Last edited: Jan 5, 2020
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    There is no other way you can input values into the Player-Action system other than through a Custom Controller.
     
    virgiliu likes this.
  45. CurryKitten

    CurryKitten

    Joined:
    Dec 22, 2016
    Posts:
    13
    It strikes me that in a case like this, the actions are the only known quantity. I could be getting any one of 16 axis as input, so hence I'd be asking "move the stick you want for roll".

    Perhaps I'm a bit on the slow side, but I personally would have liked to have seen a few more really stripped down examples in the documentation rather than large bits of code that are wrapped up on lots of GUI. Everyone's coding styles are different and there's always extra overhead for me when looking at someone elses.

    As I mentioned, I've managed to muddle through and have the input mapper and calibration working as I want it to - and it's a whole lot more successful than the base Unity stuff - so yay.

    I do have a side question though, I noticed that the inputmapper doesn't register stick movement unless it past about 50%. Is this documented, or indeed changeable anywhere. I think it might be unlikely, but I wanted to deal with a case of stick movement being 50% of the norm and this simply didn't register as an input
     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    I understand that my documentation cannot meet every single need. I've spent literally many solid months writing it as it currently stands with the equivalent of over 600 pages of information not including any of the API reference documentation or the example code. The documentation has taken far more time to write than the initial design and write of Rewired itself. There is a point where you just simply cannot spend more time writing even more documentation and tutorials. Resources and time are finite and the revenue doesn't justify it.

    Controller remapping was always considered an advanced topic from the very beginning in Rewired only suited to those who were willing to wade through code as documentation. The original release only included the single ControlRemapping1 demo and nothing else. The example code and the API documentation were the only docs on the topic. Over time, Control Mapper was developed because many developers just simply could not or would not take the time to learn the system through the example so they could have remapping out of the box with no effort. Then InputMapper was developed due to complaints that the API was too complicated and hard to understand. After that, the "Simple" remapping examples were added because again, developers didn't want to look through code. I have done so much work and spent so much time on this single area of the system, more than any other area by far, yet all of that still doesn't live up to everyone's wants.

    This value is 0.7 and is not changeable currently. It is not part of InputMapper, it's part of the Player and controller polling APIs that InputMapper uses. It is tuned to this value so detection can work with any axis regardless of the zero point without picking up connected axis accidentally in the case of sticks or 3D axes. It was tested and decided upon after testing with many different device types including gamepad sticks, flight sticks, flight pedals, flight levers, racing wheels, etc. If you have a stick that doesn't report a value more than +/- 0.7 difference from its zero point when fully engaged, the stick needs to be calibrated first before assigning so it has a proper range.
     
    Last edited: Jan 6, 2020
  47. CurryKitten

    CurryKitten

    Joined:
    Dec 22, 2016
    Posts:
    13
    Sure, I get that it's complicated. It just so happened that I needed to do controller remapping and calibration so I was diving in at the deep end. Perhaps that problem for me (and others) is that when something has a lot of options and ways of doing things, sometimes the answer to "how do I do this" is "whichever way you'd like to".

    As I said, despite my grumbling and stupid questions, my code is now working just as I want it do. Ironincally, where many of the RC radios people were attempting to use as joysticks in the normal Unity input system were going outside of the range and "looping" around prompting many to ask for a calibration - Rewired is picking up a radio that was wrapping around in Unity and treating it perfectly - so after all that to efforts to get recalibration working may be redundant :)
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    The problem you were having using Unity's input system couldn't be fixed by calibration. It's a problem at the lowest level -- reading data from the HID input report. They don't account for certain data formats and data is lost in the process. I specifically added support to handle this for these devices a long time ago. Nothing would be able to fix the problem using Unity's old input system short of replacing it, which you did.

    Axis calibration is still important because of worn out devices, etc.
     
  49. fairchild670

    fairchild670

    Joined:
    Dec 3, 2012
    Posts:
    62
    Hello,

    I was wondering if someone might have an idea on what could be causing an issue with UserDataStore_PlayerPrefs not loading user saved data when a game is loaded. I've looked through the forums and read the documentation and everything appears to be set up correctly with the ControlMapper and RewiredInputManager.

    Here's an example of where I use the ControlMapper to remap the "Exit Menu" key from "H" to "/". It appears to retain the mapped change in the current session. But once I restart the Editor the mapped change is not loaded (though mapping data was clearly written to the registry). Any help would be greatly appreciated!

     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,232
    The only way this could happen is if you are doing something that causes it to load the default configuration at some point after UserDataStore_PlayerPrefs loaded the saved data.

    I can see from your log that you are managing instantiation of the Rewired Input Manager:
    upload_2020-1-8_14-25-31.png

    If you ever disable the Rewired Input Manager Component or GameObject and re-enable it, call ReInput.Reset(), change any values in ReInput.configuration that resets the system, call Player.controllers.maps.LoadDefaultMaps, destroy the Rewired Input Manager and reinstantiate it, etc., the loaded saved data will be cleared, the defaults loaded, and you'd get the result you see. If you do any of this, you will have to manually call ReInput.userDataStore.Load to force it to load the saved data again.
     
    Last edited: Jan 8, 2020
    fairchild670 likes this.
unityunity