Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    5,605
    :)

    Glad it works!
     
  2. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85
    Hi @guavaman ,
    I want to create an axis which should only have a range from 0 to 1 never go below 0.
    there will be button having +ve and -ve contribution but axis should never fall below 0.
    how should I go about doing this?
    Thanks in advance.
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Please clarify the context. Are you trying to create:
    1. A ControllerMap Action -> Element mapping. If so, what is the map type and what type of input source will be mapped to this Action?
    2. A Custom Controller element.
    3. An element on a HardwareJoystickMap controller definition.
    If you are creating an Axis-type Action that will have a joystick axis mapped to it, set the Axis Range to Positive or Negative depending on which side of the axis you want to trigger it and set the Axis Contribution to Positive.

    If you want to map "Left Stick X, Right" to the Action "Move", set Axis Range to Positive and Axis Contribution to Positive.
     
  4. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85
    It is an Axis-Type action, but will be controlled by buttons.
    I want the D-pad to control the axis value,
    D-pad up - 'increase',
    D-pad down, 'decrease',
    while being limited between 0 and 1

    But now that I think about it, this will have to be done in code, unless, you suggest an alternative.

    Thanks

     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    So you're trying to make a throttle basically. I have to guess that you want the value to persist after the user releases the button, because if not, D-pad down "decrease" would have no purpose.

    There is no way to clamp an Action's value to only positive or negative, so there's no way to do what you want to do directly. You can make an Action's value stick when controlled by a button by setting the Input Behavior's Digital Axis Gravity to 0 and disabling Digital Axis Instant Reverse and Digital Axis Snap. This will make the Action stay at the last state until modified, but the value will be allowed to go below 0.

    In order to do it, you would have to do it in code. Do not set the Input Behavior Digital Axis Gravity to 0. Assign D-Pad Up to Throttle + and D-Pad Down to Throttle -.

    Code (csharp):
    1. // throttleSpeed controls how fast the throttle speed ramps up or down as the user holds the button
    2. float GetThrottle(Player player, float throttle, float throttleSpeed) {
    3.     if(player.GetButton("Throttle")) throttle = Mathf.Clamp01(throttle + (throttleSpeed * Time.unscaledDeltaTime));
    4.     else if(player.GetNegativeButton("Throttle")) throttle = Mathf.Clamp01(throttle - (throttleSpeed * Time.unscaledDeltaTime));
    5.     return throttle;
    6. }
     
    Last edited: Aug 16, 2016
    vivalavida likes this.
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Rewired 1.0.0.96 is now available on the Unity Asset Store.

    Please be sure to read Updating Rewired before updating.

    1.0.0.96:

    Changes:
    - Windows Standalone Direct Input and XInput: Improved accuracy of button down detection when frame rate is extremely low and a button is pressed and released quickly.
    - ReInput.ControllerHelper.GetLastActiveController is now based on controller element value changes instead of absolute element values to exclude uncalibrated non-zero-at-rest axes and always-on buttons.
    - ReInput.ControllerHelper.GetLastActiveController() now returns Keyboard if no last active controller is found.
    - Added Debug Information to Rewired Input Manager inspector. This shows a ton of useful information allowing you to visualize most objects in the system during runtime.
    - Minor performance optimizations.

    API Changes:
    - Added Controller.GetButtonChanged method.
    - Added Controller.GetAnyButtonChanged method.
    - Added Controller.GetLastTimeAnyButtonChanged method.
    - Added Controller.GetLastTimeAnyElementChanged method.
    - Added Controller.Button.lastTimeStateChanged property.
    - Added Controller.Button.justChangedState property.
    - Added Controller.Axis.lastTimeValueChanged property.
    - Added Controller.Axis.lastTimeValueChangedRaw property.
    - Added ControllerWithAxes.GetLastTimeAnyAxisChanged method.
    - Added ReInput.ControllerHelper.GetAnyButtonChanged method.
    - Added ReInput.ControllerHelper.GetLastActiveControllerType method.
    - Removed obsolete ActionElementMap.actionCategoryId property.
     
  7. funselektor

    funselektor

    Joined:
    Oct 11, 2013
    Posts:
    105
    Hey there,

    I just pushed a big update to my game with Rewired, so I'm going through a few bug reports.

    It seems like this exception with PS4 controllers has been popping up quite a bit, is there something I'm doing wrong?
    Using Rewired 1.0.0.94

    upload_2016-8-17_23-16-37.png
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    There's no context for me to understand what's going on. Do you have any reports from users giving any clue as to when/how this is happening?

    After combing through the code, I believe I have an idea what may be happening, but the scenario would be very rare involving disconnecting and reconnecting a device with it failing to initialize the device with special feature support the 2nd time due to some other process having an exclusive lock on the device. (Or some other unknown error on 2nd initialization causing it to fail and fall back to no special feature support.)

    Your only option right now is to disable Enhanced Device Support which will disable vibration support for DS4. I will make changes to prevent the exceptions in this edge case, but if what I believe is happening is, special features of the DS4 in these odd cases will be disabled including vibration and there would be no way around this because it's not possible to force unlock the device.
     
    Last edited: Aug 18, 2016
  9. funselektor

    funselektor

    Joined:
    Oct 11, 2013
    Posts:
    105
    Sorry about the limited information. The only thing users have said is their PS4 controller is not working, but sometimes vibration-only will work"
    "On SteamOS, the PS4 controller doesn't work at all, Strangely, the vibration works. (if I play with the keyboard and leave the controller on)"

    The log file is attached!

    Here is some code we are using for controller connects/disconnects. This was to pass CERT on PS4 as their was a bug with quickly plugging & unplugging controllers, but do you think this could let some bugs through otherwise?
    ----------------------
    private static void Init()
    {
    if(!initialized)
    {
    initialized = true;

    ReInput.ControllerConnectedEvent += JoystickConnected;
    ReInput.ControllerDisconnectedEvent += JoystickDisconnected; // final disconnect that runs after joystick has been fully removed
    }
    }

    private static void JoystickConnected(ControllerStatusChangedEventArgs args)
    {
    if (bDefaultMapEnabled)
    EnableDefaultMap(true);

    if (bUIMapEnabled)
    EnableUIMap(true);

    if (bReplayMapEnabled)
    EnableReplayMap(true);
    }
    ----------------------

    And here are my Platform Settings if it helps (I will disable Enhanced Device Support and update Rewired to the latest version):
    WINDOWS
    upload_2016-8-18_9-10-2.png

    OSX
    upload_2016-8-18_9-23-28.png

    LINUX
    upload_2016-8-18_9-23-6.png

    Also an issue with Xbox360 controllers, they don't seem to be showing up for some people:
    upload_2016-8-18_9-12-6.png

    And this was a workaround for another user:
    If you have a controller, check your Windows settings to see if your controller's name is there with another "Xbox 360 controller for Windows" in your devices. Then, uninstall the 360 controller, leaving just your controller. Not sure if this was a Windows thing or a game issue.
     

    Attached Files:

  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Thanks for all the info!
    Every platform is entirely different. There is no relation between DS4 on Windows and DS4 on Linux, so I will address each of these issues individually..

    DS4 on Linux:
    The DS4 on Linux does not use any special-case code. It is treated as a standard HID device. The only way this device could fail to work is if SteamOS uses a different driver than Ubuntu which is the supported OS. The fact that the user says the device vibrates indeed sounds like a different driver is being used.

    Additionally, "doesn't work" almost always means the Joystick doesn't automatically get mapped by the Dual Analog Gamepad Template and just work out of the box . If a controller is not recognized, it will show up as an Unknown Controller which will not work automatically but can be made to work through the use of user remapping. Do you have a way for users to map their controllers in-game?

    I don't see any information logged at all by Rewired so there aren't any errors. However, I do see this which must be your system logging some info:

    Got value 1.00 on unmapped axis 7
    Got value 1.00 on unmapped axis 6

    If that information is coming from your code based on information from a Rewired Joystick, it indeed appears the Joystick is not recognized due to different device identifying information, probably due to a different driver. This isn't a problem if you have a remapping system for the users. Based on the number of axes, I'm guessing the driver supports the gyro on SteamOS. Of course, if the gyro is enabled and set up as standard axes, remapping would be foiled by the rapidly changing values in these axes.

    I am going to attempt to set up a Steam OS VM and see if I can get the information to support the DS4 on this platform.

    Are you using "Native" input on PS4? Events are sent from UnityEngine.PS4Input when controllers are connected/disconnected. Otherwise, it has to poll Input.GetJoystickNames every 1 second to detect controller changes.

    I don't see any problems with that code. You're doing it correctly, except EnableDefaultMap, etc. don't appear to be referencing any JoystickId. args contains the controller type (always Joystick for now) and the Joystick Id of the joystick that was connected/disconnected. Are you just setting those map categories enabled across all devices when any joystick is attached?

    You've got Use XInput enabled, so these controllers are being handled by XInput. There's nothing that can be done to change anything on the XInput side of things. XInput is extremely simple and does not have any options to change its behavior. If Use XInput is enabled and the user isn't able to see his XInput compatible controller, there has to be something wrong with the controller or the system. They would be having the same problems with any game that uses XInput. Using XInput is the most fool-proof way of supporting XInput compatible controllers.

    If for some reason XInput is not installed (user is on XP) or Rewired cannot initialize XInput for some other reason, it will log it in the log file. However, if XInput doesn't init, it will just fall back to Raw Input which also has no issue with the Xbox 360 Controller.
     
    Last edited: Aug 18, 2016
    funselektor likes this.
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    @Little_Gorilla

    One more thing with regards to the Xbox 360 issue. If you've left the default Joystick Auto-Assignment settings, the user may simple have multiple controllers connected without realizing it (or some always-present virtual HID joystick). See this Troubleshooting topic for explanation and solutions. The section entitled "More reasons why your controller may appear not to work:"
     
  12. funselektor

    funselektor

    Joined:
    Oct 11, 2013
    Posts:
    105
    There is no in-game controller mapping. But I am using that Dual Analog Template. Should I make a specific map for the Dualshock 4.

    Or could it be that they have another input device (ie. an unsupported joystick) and that is messing up things?

    upload_2016-8-18_11-33-24.png

    Yes I'm using Native Input for PS4. To be clear, it's all good on PS4!

    I attached the full class from that code snippet. Yes I think I am setting it across all controllers, but the Joystick ID is hardcoded to 0, perhaps it should also set the "args.controllerID" variable too?

    Rewired.ReInput.players.GetPlayer(0).controllers.maps.LoadMap(Rewired.ControllerType.Keyboard, 0, RewiredCategoryName.ReplayName, LAYOUT_1_ID, true);
    Rewired.ReInput.players.GetPlayer(0).controllers.maps.LoadMap(Rewired.ControllerType.Joystick, 0, RewiredCategoryName.ReplayName, LayoutIDList[SaveGame.GetInt(PlayerPrefsConstants.GAME_SETTINGS_CONTROLLER_LAYOUT, 0)], true);


    OK I will tell players to check their drivers for this bug.

    Thanks for the detailed responses so far! :)

     

    Attached Files:

  13. funselektor

    funselektor

    Joined:
    Oct 11, 2013
    Posts:
    105
    Oh, good call, I raised the Max Joysticks Per Player to 8. This should fix a lot of issues for players!
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    No, making a specific mapping for DualShock 4 won't help anything because if the device is not recognized (ie: it doesn't match Vid/Pid or Product Name) it will not use the DualShock 4 map because it doesn't know it's a DualShock 4. If SteamOS has a driver that returns different info, it won't be recognized. I'll let you know when I get SteamOS up.

    It's possible depending on your Max Joysticks Per Player settings if this is a 1-Player game.

    Okay, thanks for clearing that up!

    Thanks for sending that!

    Yeah, do not pass 0 for the Joystick Id unless the Joystick Id is 0. It's not an index, it's a unique id. If your user plugins in one type of controller, then removes it and plugs in another type, the second will be Id 1 and your code will never apply the changes. Keyboard and mouse are always 0 though.

    Code (csharp):
    1. Rewired.ReInput.players.GetPlayer(0).controllers.maps.LoadMap(Rewired.ControllerType.Joystick, 0, RewiredCategoryName.UIName, LayoutIDList[SaveGame.GetInt(PlayerPrefsConstants.GAME_SETTINGS_CONTROLLER_LAYOUT, 0)], true);
    Change the above code (Line 74) to the following which will load the maps for all Joysticks assigned to the Player:

    Code (csharp):
    1. foreach(Joystick joy in Rewired.ReInput.players.GetPlayer(0).controllers.Joysticks) {
    2.     Rewired.ReInput.players.GetPlayer(0).controllers.maps.LoadMap(Rewired.ControllerType.Joystick, joy.id, RewiredCategoryName.UIName, LayoutIDList[SaveGame.GetInt(PlayerPrefsConstants.GAME_SETTINGS_CONTROLLER_LAYOUT, 0)], true);
    3. }
    It's not at all important but this code:

    Code (csharp):
    1. foreach (ControllerMap map in Rewired.ReInput.players.GetPlayer(0).controllers.maps.GetAllMapsInCategory(RewiredCategoryName.DefaultName)) {
    2.     map.enabled = false; // set the enabled state on the map
    3. }
    Can be replaced with this:
    Code (csharp):
    1. Rewired.ReInput.players.GetPlayer(0).controllers.maps.SetMapsEnabled(false, RewiredCategoryName.DefaultName);
    Again, not important but the code might be a bit more readable if you get the Player once per method instead of having Rewired.ReInput.players.GetPlayer(0) in every call.

    If you can, try to get a log file from one of them to see if XInput can't initialize. Rewired attempts to find any version of XInput starting with 1.3, then 1.4, then backwards down to the original.
     
  15. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    @Little_Gorilla There are quite a few more calls for LoadMap that need to be iterated for all joystick id's and twofor CustomController id. Here is the fixed version.
     

    Attached Files:

    Last edited: Aug 18, 2016
  16. funselektor

    funselektor

    Joined:
    Oct 11, 2013
    Posts:
    105
    I've checked the logs for problems with XInput and haven't been able to find any initialization problems yet.

    This was a problem in the past (pre-Rewired integration), but now the installer contains DirectX (June 2010), so this hasn't been a problem since then.

    Wow thank you so much, I really appreciate you taking the time to fix my code!
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Thanks for the update! Glad to help.

    After fighting all day long with SteamOS, VirtualBox, and VMWare, I finally was able to get SteamOS half-way working using a different deskop, but it was good enough to get the DS4 info. Sure enough, the driver was changed. I've got the info now and will include the SteamOS variant in the next update along with the other fixes mentioned above. I will probably push this out today or tomorrow.
     
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Rewired 1.0.0.97 is available for registered users to download on the website now. If you'd like to register to receive early access to updates, please contact me here. The Unity Asset Store should have this update in 3-10 business days.

    1.0.0.97:

    Changes:
    - Added Player Actions to Rewired Input Manager Debug Information.
    - Added Exclude From Polling property to axes in HardwareJoystickMap
    - Arrow keys are now enabled on Android even when keyboard is set to disabled to allow remotes to work.
    - Minor optimizations.

    Modified Controller Definitions:
    - DualShock 4, Linux Native: Added SteamOS variant.
    - Apple Siri Remote, iOS: Excluded accelerometer and gyro axes from polling.

    Bug Fixes:
    - Windows Standalone Raw Input: Handled edge case of DualShock 4 being connected first with special feature support, then being disconnected and reconnected, and being unable to initialize special feature support due to some other process taking an exclusive lock on the device.
    - ControlRemappingDemo1.cs: Changed code to accomodate a Unity bug with preprocessor if.
    - Re-exposed Consts class due to breaking certain integration packages.
    - Updated Control Mapper for changes made in Unity 5.3 that broke calibration window axis buttons.
     
    Last edited: Aug 22, 2016
  19. funselektor

    funselektor

    Joined:
    Oct 11, 2013
    Posts:
    105
    Awesome, thanks so much!
     
  20. kurismakku

    kurismakku

    Joined:
    Sep 18, 2013
    Posts:
    66
    Hi :)

    I am testing PS4 gamepad on OSX with Trial version. Problem is that the gamepad sometimes work, sometimes doesn't.
    It returns false for every key check on gamepad, but for keyboard it works. Xbox 360 gamepad works as well.
    I created PS4 joystick map, but it didn't fix the problem. In PS4 settings, Input Source is set to Unity.


    Also, I noticed that when I check keyboard presses with Rewired, I don't get the same results as I do when I use standard Unity Input. It seems that during some frames the checks return false even though I am holding key for the whole time.
     
    Last edited: Aug 19, 2016
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    What returns false?

    You are testing on OSX, not the PS4. PS4 settings do not apply to OSX. Only OSX settings apply to OSX.

    If you are using Unity Input as the source on OSX, is your DS4 connected via USB or Bluetooth? If you look at the Supported Controllers page, you will see the DS4 on Bluetooth when using Unity Input does not work right with the D-Pad inaccessible:


    DS4OSX.png

    Rewired uses UnityEngine.Input for all keyboard input, so there's no possibility of differences in key behavior. The only things that could affect the behavior is mappings or InputBehavior settings.

    Please post the code you are using to check the value of the key and specify whether this is being called from Update, FixedUpdate, or from within a coroutine.
     
    Last edited: Aug 20, 2016
    kurismakku likes this.
  22. kurismakku

    kurismakku

    Joined:
    Sep 18, 2013
    Posts:
    66
    Thank you for the quick answer! :)


    DS4 is connected via USB.

    I tested more, and I noticed that gamepad doesn't activate if I press something on the keyboard.
    Also, my gamepad sometimes disconnects, I was thinking the problem is in Rewired, but the same happened while using OpenEmu. This two in combination together really confused me.

    It happened once that I used gamepad first, so keyboard became disabled. But than after gamepad was disconnected, I wasn't able to use anything. I tried reconnecting it few times, but it didn't help until I restarted the game.

    This reminded me that Enter the Gungeon had a "bug" in which if you press something on keyboard at start of the game, you wasn't able to use gamepad anymore. Is there any way to avoid this behavior or enable that the player can switch it inside of the game, in options?


    The code is called from Update. The gamepad is disconnected, I use keyboard.

    What happens is this : when I press the key, it is registered, but than after I stop pressing it, it registers that it is still pressed for around the half of second. This causes that the player slides around the screen.

    Here is the code that is called EVERY frame :

    Code (CSharp):
    1. isMovingUp = input.isMoveUpPressed;
    2. isMovingDown = input.isMoveDownPressed;
    3. isMovingLeft = input.isMoveLeftPressed;
    4. isMovingRight = input.isMoveRightPressed;
    5.  
    6. log(isMovingUp, isMovingDown, isMovingLeft, isMovingRight);
    7. // here I clearly see that some flags are true even though I am not pressing any button
    8.  
    9.  
    10. public bool isMoveUpPressed
    11. {
    12. get
    13. {
    14. Debug.Log (rewiredPlayer == null); // this always returns false
    15. Debug.Log (rewiredPlayer.GetAxis (GGRewiredActions.Game_Move_Vertical) > 0); // this returns true for x frames after I stop pressing button
    16. return rewiredPlayer == null ? false : rewiredPlayer.GetAxis (GGRewiredActions.Game_Move_Vertical) > 0;
    17. }
    18. }
    19.  
    20. [Rewired.Dev.ActionIdFieldInfo(categoryName = "Game", friendlyName = "MoveVertical")]
    21. public const int Game_Move_Vertical = 2;
    22. [Rewired.Dev.ActionIdFieldInfo(categoryName = "Game", friendlyName = "MoveHorizontal")]
    23. public const int Game_Move_Horizontal = 3;
    24.  
    25.  
     
    Last edited: Aug 20, 2016
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    That's not what's happening here. There is another issue going on, most likely mapping related. Keyboard input does not interfere with joystick input as they are entirely separate systems.

    I don't really understand what you are describing with the gamepad and keyboard. But you can use the Debug Information in the Rewired Input Manager inspector to see what joysticks are assigned to the Player, what maps are assigned, and even what controller buttons/axes are currently pressed. You can probably find the reason for your issues by looking through this information.

    As for joystick disconnection, the only way that would happen is if you have either a bad DS4, a bad USB cable, or a bad USB port.

    You can also test using the 8 Player Demo in the Examples folder. The first player can be controlled with a gamepad and the wasd keys. If this exhibits the same behavior where the keyboard/gamepad interfere, then there has to be a hardware problem with your computer. If not, then you know the problem is in your code/configuration.

    The bold line of code is the reason for this behavior. You're getting the axis value for the Action from a button and returning true if the value is non-zero. When you call GetAxis on an Action mapped to a physical button, Input Behavior Digital Axis settings comes into play:

    Input Behaviors

    Digital Axis Settings

    These settings allow buttons and keyboard keys to be treated like axes and return values ranging from -1 to 1 instead of just True and False as is the usual case. This allows you, for instance, to have smooth character movement when using the keyboard for movement controls. The GetAxis value of the Action can be smoothed over time based on the Digital Axis Settings (gravity and sensitivity). See Rewired Editor - Input Behaviors for more information about each setting.

    --------------------

    The defaults of Gravity = 3, Sensitivity = 3 are set to mirror the defaults of Unity's input system. It makes axis values ramp up and down for button presses instead of being instant on/off. This allows for smooth character movement when using the keyboard. Float the cursor over these properties in the Input Behavior to see help for each property. Set Gravity = 1000, sensitivity = 1000 for instant on/off.

    Or. more simply, just call GetButton instead of GetAxis if all you're interested in is an On/Off value. GetAxisRaw will also return just 1 or 0 for a button.
     
    Last edited: Aug 20, 2016
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Rewired 1.0.0.96 made the Rewired.Consts class internal, which inadvertently broke the PlayMaker, BehaviorDesigner, and UFPS integrations which each relied on 1 const in that class. PM and BD integrations can be fixed by replacing Consts.systemPlayerId with 9999999, and the UFPS integration can be fixed by replacing Consts.menuRoot with "Window/Rewired". The fix is already included in 1.0.0.97 which will be on the store in a few days and is available now for registered users.
     
    clarson2974 likes this.
  25. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    136
    Hi Guavaman,
    I need a particular input behaviour that I can't come up with a solution for so any help would be great. Similar to the increment question posted above:

    I have one input action, lets call it "bias" mapped as an axis.

    This singular Axis needs to have an incremental digital ramp(button), but also an analogue throttle(axis). So in one instance, hitting Key A should add +1% while holding, Key B should be -1%. At any given moment, a user should be able to use a physical throttle to hold it at, say, 33%, now ignoring the digital inputs, and vice versa.

    I have tried this, which works moderately well, but sort of a hack:

    Code (JavaScript):
    1.  
    2. inBias = player.GetAxis("Bias");
    3.  
    4. if((inBias == 0 || inBias == 1 || inBias == -1)){biasLock = true;}
    5. else{biasLock = false;}
    6.  
    7. if(biasLock){
    8.     if (inBias < -0.98) {
    9.         bias-= 0.001f;
    10.     }
    11.     else if (inBias > 0.98) {
    12.         bias += 0.001f;
    13.     }
    14. }
    15. else{
    16.     bias = (inBias * 0.5) +0.5;
    17. }
    18.  
    19.  
    Ideally, I would detect if the Axis input is digital or analogue, and set the lock appropriately, but as far as I can tell, that doesn't exist. Any thoughts?
    Thanks
    -Ryan
     
  26. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    255
    Hi @guavaman ,

    I am seeing an issue with the ControlMapper in 5.4. I don't think it was there in 5.3.#
    The buttons in the left panel of the calibration window are not visibly deselecting. So as you click on the buttons one by one they will all end up being selected. This is only a visual as the buttons actions are showing the correct item to calibrate each time.

    I have this happening in my menu so I started a fresh project and tried just rewired and it happens there too. I was not on the very latest so I updated to be sure and it made no difference.


    Any ideas?

    Ben
    upload_2016-8-22_13-43-24.png
    upload_2016-8-22_13-43-24.png
     
  27. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    How To's - Getting contributing input sources for an Action

    If you must differentiate your controls based on the physical element type, that is the only way.

    Doing what you want to do might be easier with two or three separate Actions though. One version for analog throttle controls, one version for button controls. BiasStepUp, BiasStepDown, Bias or something like that. Then you can map them based on the element type and in your code, if both are returning value, prefer Bias over the others.
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Works perfectly in Unity 4.6 and 5. Unity broke something. Now I have to dissect their system and figure out what they did and how to work around it and make it work on old versions too.
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    @Baraff

    Edit Rewired/Extras/ControlMapper/Scripts/CalibrationWindow.cs.

    At line 397, add the code below:

    Code (csharp):
    1. #if UNITY_5_3_OR_NEWER
    2.     axisButtons[index].Select();
    3. #endif
    It should look like this starting at line 393:

    Code (csharp):
    1. private void SelectAxis(int index) {
    2.             if(index < 0 || index >= axisButtons.Count) return;
    3.             if(axisButtons[index] == null) return;
    4.             axisButtons[index].interactable = false; // disable this axis
    5. #if UNITY_5_3_OR_NEWER
    6.             axisButtons[index].Select();
    7. #endif
    They decided to change the system so when Selectable.interactable is set to false, the Selectable gets immediately deselected. This caused all the problems because the buttons were immediately deselected after being activated and set to non-interactable. This is actually happening to all the buttons in Control Mapper, but on the main screen, there was already a system in place to automatically reselect the last selected button when deselected so as to prevent deselection and making joystick navigation impossible. This was automatically reselecting the button after Unity deselected it on interactable = false. This made most of Control Mapper just continue working after this change. The popup windows do not have the same auto-reselection as the main window.
     
    Last edited: Aug 22, 2016
  30. LunaTrap

    LunaTrap

    Joined:
    Apr 10, 2015
    Posts:
    120
    Hi, i have a question, take a look at how much rewired input manager is using
    is it me or is this too much? i have used rewired on all my prototypes and i never saw so much use, why? 0.50ms is way too much, i never saw so much use from it.

    I was worried it had something to do with something i was doing, so this screenshot was taken in an empty scene with only my rewired input manager, im worried.
     

    Attached Files:

    Last edited: Aug 22, 2016
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    How To's - Optimizing Performance

    In addition to that information, if you are using input events, you are putting the burden of polling for input events on Rewired instead of your scripts which increases its apparent CPU usage. Not only that, but any code that is run in the event callback will be attributed to InputManager_Base instead of your script.
     
  32. guavaman

    guavaman

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

    1.0.0.97:

    Changes:
    - Added Player Actions to Rewired Input Manager Debug Information.
    - Added Exclude From Polling property to axes in HardwareJoystickMap
    - Arrow keys are now enabled on Android even when keyboard is set to disabled to allow remotes to work.
    - Minor optimizations.

    Modified Controller Definitions:
    - DualShock 4, Linux Native: Added SteamOS variant.
    - Apple Siri Remote, iOS: Excluded accelerometer and gyro axes from polling.

    Bug Fixes:
    - Windows Standalone Raw Input: Handled edge case of DualShock 4 being connected first with special feature support, then being disconnected and reconnected, and being unable to initialize special feature support due to some other process taking an exclusive lock on the device.
    - ControlRemappingDemo1.cs: Changed code to accomodate a Unity bug with preprocessor if.
    - Re-exposed Consts class due to breaking certain integration packages.
    - Updated Control Mapper for changes made in Unity 5.3 that broke calibration window axis buttons.
     
  33. LunaTrap

    LunaTrap

    Joined:
    Apr 10, 2015
    Posts:
    120
    Thanks a lot for the tips, i was using string constants for managing input, im very dumbd i forgot it works with int also

    one last things, so if i understand correctly?

    "Note: Unity's profiler in Debug builds tends to report significantly inflated CPU usage for Rewired's InputManager_Base.Update."

    does this means the what the profiler is showing is not te actual usage the input manager is using?
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    It depends. Release builds run faster than debug builds, and deep profile is just wrong because of all the overhead. You cannot use Unity's profiler in a release build, but when timed with System.Diagnostics.Stopwatch, the InputManager_Update is significantly faster than what the profiler reports in a debug build.
     
  35. RedRiverStudio

    RedRiverStudio

    Joined:
    Sep 8, 2014
    Posts:
    136
    I definitely can't do that. All good, I will try out the input source functions. Thanks for the response!
     
    guavaman likes this.
  36. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    255
    Thanks @guavaman. Grabbed the updated version in which you have already made the change also. Brilliantly quick.
     
    guavaman likes this.
  37. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    255
    I am looking to create a simple Invert toggle on the Y axis for players. I know the calibration popup allows for Inverting quite nicely, however if the player does this, it means that the all the menu navigation will also be inverted which is not really the intention. So if I create a simple toggle instead, this can be checked as the actual gameplay starts and Invert if required. The calibration window code will rightly create a button for all axis. Is there a simple way to know which will be the Y axis and set a toggle for that?

    Update: On thinking some more I decided I should be able to use a new map category set up just to Invert Y. So I am looking at that now.
     
    Last edited: Aug 23, 2016
  38. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Rewired supports inversion for the hardware axis in AxisCalibration and for the Action mapping in ActionElementMap. You should be using the ActionElementMap version and not the hardware version if you are trying to invert values for only a specific Action or mapping. Control Mapper illustrates this feature.
     
  39. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    255
    Thanks. I got a simple toggle working for Invert but I am having difficulty finding how to stop the Invert button appearing in the calibration. I tried commenting out all references to toggle in CalibrationWindow.cs but the button still appears, so I am assuming that is not the correct way to do it. Sure, they don't do anything now, but I am missing something. Where else should I look or how else should this be done?
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    I don't recommend removing the hardware invert. The user may need it if the joystick is unrecognized because almost all joysticks use negative Y for up. Unrecognized controllers' axes will be raw and sticks will be inverted. The user can use this hardware inversion to fix the axis universally.

    If you want to remove the button in Control Mapper, you will have to edit the prefab for the calibration window. Those elements are not dynamically generated. Once you do, every update of Rewired will overwrite the prefab. You will have to follow the procedures outlined here in the Control Mapper FAQ under the heading: Q: I want to customize more than what's available in the theme settings. How do I do that?
     
  41. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    255
    Thanks. That makes sense. I think I will leave it as is then.
     
  42. Roffy437

    Roffy437

    Joined:
    Jan 23, 2015
    Posts:
    24
    Hello, we are interested in your plugin, but I'd like to know if it is possible to manage keyboards whatever the localization. For example, we want that if a player has an AZERTY keyboard, then a possible default WASP input to move a character automatically will become a ZQSD input, without the player have to change the binding himself. I have tested the free trial of Rewired a few, and it seems that you use keycodes to detect the keys. Do you know how can I do that ? If I am not enough clear I can be more verbose.

    Thank you,
    Mathieu
     
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Hi,

    No. At this point in time, Rewired wraps UnityEngine.Input.GetKey for all keyboard input.
     
  44. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Hey @guavaman I was attempting to find out which kind of controller my player was using (xbox, ps4, mouse/keyboard) in order to display a "press this button" on the screen that represents their current controller.

    The game input is fairly simple, single player, is there a straightforward way of checking this out? Thanks
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    http://guavaman.com/projects/rewired/docs/HowTos.html#get-element-name-for-action
    http://guavaman.com/projects/rewired/docs/HowTos.html#display-glyph-for-action
    http://guavaman.com/projects/rewired/docs/HowTos.html#identifying-recognized-controllers
     
    Last edited: Aug 25, 2016
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Rewired 1.0.0.98 is now live on the Unity Asset Store!

    1.0.0.98:

    Changes:
    - Added Digital Axis Simulation option in Input Behavior to disable digital axis simulation more easily.
    - Performance improvements.

    API Changes:
    - Added InputBehavior.digitalAxisSimulation property.
    - Added ReInput.ControllerHelper.AutoAssignJoystick method.
    - Added ReInput.ControllerHelper.AutoAssignJoysticks method.
    - Added ReInput.ControllerHelper.AddLastActiveControllerChangedDelegate method.
    - Added ReInput.ControllerHelper.RemoveLastActiveControllerChangedDelegate method.
    - Added ReInput.ControllerHelper.ClearLastActiveControllerChangedDelegates method.
    - Added Player.ControllerHelper.AddLastActiveControllerChangedDelegate method.
    - Added Player.ControllerHelper.RemoveLastActiveControllerChangedDelegate method.
    - Added Player.ControllerHelper.ClearLastActiveControllerChangedDelegates method.
    - Added ActiveControllerChangedDelegate delegate.
    - Added PlayerActiveControllerChangedDelegate delegate.

    Integration Changes:
    - Added RewiredPlayerInputBehaviorGetDigitalAxisSimulation Behavior Designer Task.
    - Added RewiredPlayerInputBehaviorSetDigitalAxisSimulation Behavior Designer Task.
    - Added RewiredPlayerInputBehaviorGetDigitalAxisSimulation PlayMaker Action.
    - Added RewiredPlayerInputBehaviorSetDigitalAxisSimulation PlayMaker Action.
     
  47. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    I didn't notice you also wanted to detect whether they are using the keyboard or mouse. This one is for that:
    http://guavaman.com/projects/rewired/docs/HowTos.html#last-used-controller
     
  49. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,605
    Rewired 1.0.0.99 is available for registered users to download immediately. If you'd like to register for early access to updates, please contact me here.

    1.0.0.99:
    Bug Fixes:
    - Fixed null reference exception when calling Player.IsCurrentInputSource introduced in 1.0.0.98.

    A bug was introduced in 1.0.0.98 due to optimizations made to the system responsible for Action values. When calling any of the contributing input source methods in Player before any actual input is received for that particular Action, a null reference exception was thrown. This release is nothing but a bug fix for that. If your game uses any of the contributing input source methods, do not update to 1.0.0.98 and go straight to 1.0.0.99.
     
    Last edited: Aug 27, 2016