A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Discussion in 'Assets and Asset Store' started by guavaman, Sep 25, 2014.
The documentation was written before the release was finalized. Thanks!
I just started to evaluate Rewired for our new project. Damn this asset realy blew my mind...
I'm just having one problem I can't figure out:
The player can have multiple controllers he uses simultaneously, e.g. 2 Logitech Joystick and the left one controls the camera and the right one controls the charactermovement (this is just a simplyfied example).
Right now I have a JoystickMap where StickX/Y is contained 2 times. Once for the cameraMovement-Action and once for the characterMovement-Action. My Script just uses Player.GetAxis(actionName).
If I now use any of the Joystick, obviously the character walks and the camera moves at the same time (on both Joysticks).
I found nothing in your documentation/forum/reddit/... to solve this or better, what would be the correct way to implement this with rewired. If this is a dumb questions, any links would be great
You cannot configure separate default Controller Maps for two identical joysticks to be assigned to the same Player in the Rewired Editor. This is beyond the capabilities of the system. This advanced use case can only be handled by manually managing all Controller Maps yourself:
Create multiple Controller Maps, either in different Categories or Layouts.
Write a script to detect when 2 of the joystick you're looking for are assigned to the same Player.
Unload the existing maps from the 2nd and load the maps you made for the 2nd controller.
Another way to handle it without managing maps using scripts is to use 2 separate Players as a single Player. Assign each different Controller Maps. Get input from both Players.
Thanks! I thought that I have to do something like this...
Using seperate Players sounds like an option I would like to try out, but I have a followup question about that.
Would you recommend adding new players at runtime via "ReInput.players.Players.Add()" ? Maybe from a template Player-Object. Or should I generate a couple of them in the editor? Asking because it occured in an older version of the game series that players wanted to use up to 6 or 7 different controllers.
You cannot add Players at runtime. Players are created when Rewired initializes based on the settings in the Rewired Input Manager and cannot be created or destroyed at runtime.
If the game is multi-player or you want to use Control Mapper to allow them to rebind controls and don't want to build your own system, do not use multiple Players and instead manage your Controller Maps manually. Managing the maps manually is the most robust way.
Having as many controllers as you want at once isn't a problem. The only problem is defining different default mappings for multiple of the same controller for the same Player.
I am aware that Rewired only supports fully-released versions of Unity. This post is meant to be informational.
When trying to build a 2019.1.x project that contains Rewired, I get multiple errors in the ControllerMapper add-on. This is apparently because Unity removed the List<Selectable> API for Selectable.allSelectables. I noticed a bug was opened (below) that claims this will be fixed in 2019.1.
I just found out on a forum post (below) that "Fixed" is actually "Resolved: Won't Fix". Rewired's API will need to be updated to accept arrays instead of lists. Apparently, they have also added a no-alloc version that accepts reference Array parameters.
Thanks for the report. I will take it into consideration when making the Unity 2019 branch.
In my testing with Unity 2019.1.0b6, this isn't the only problem with Control Mapper. UI drawing on Control Mapper has all kinds of new problems including buttons becoming black instead of being highlighted and bright flashes as the UI is initially drawn on cursory preliminary testing. Code that has worked on all versions of Unity going back to 4.6 is now broken and showing artifacts in Unity 2019. I'm going to have to 1) figure out why 2) find workarounds if possible. If changes to the 2019 UI code have caused these problems in Control Mapper, it's likely they've also caused problems in Touch Controls as well.
Hi Guavaman! I imported your asset into my 8-player game after I initially failed the Steam "full controller support" test and needed to do more things with controllers. I'm loving it!
I have one problem right now: I just bought some cheap SNES style controllers off of Amazon that are definitely unrecognized (they say unrecognized and have 32 axes in Rewired debug).
Via your documentation here (http://guavaman.com/projects/rewired/docs/ControllerMaps.html) I would think these would fall back to the "Unknown Controller Map" as mentioned on that page.
However they do not fall back properly, or the Unknown Controller Map is not mapped to the "standard" gamepad controls, since Axis 0 and 1 are definitely the "main" D-pad axes on these controllers, and the 4 buttons are mapped to the typical 0,1,2,3, yet they do not control the main menu or any other screen of my game in builds using Rewired. In previous builds of my game (before I implemented Rewired), I have checked and these new controllers do actually work since they match the "standard" gamepad button mappings, which I had Unity Input defined for.
So this leads me to believe that I need to actually create my own "Unknown Controller Map" to get this to work, or something is wrong with my specific Rewired instance. I don't actually see any info on how to create an "Unkown Controller Map" but I assume it's somewhere in the Custom Controller section?
In case you need this info, I am using Rewired 220.127.116.11.U2018. Thanks in advance!
Edit: Welp, looks like I found it! It's right under the templates in the "Joystick Maps" tab for anyone looking. I defined my actions for Axis 1 and 0 and the buttons and got it working. But shouldn't the actions mapped on the default gamepad template work for unknown controllers without separately defining them? It seems like that should be possible.
This is documented here:
No, unrecognized controllers cannot possibly work with the Gamepad Template. Controller Templates require the metadata provided by the controller definitions that have been created for each supported controller to work, plus the Template itself must also have a Controller to Template mapping to support the Controller. Controller Templates are explained here:
This is specifically addressed:
NOTE: Do not be confused and assume that the Gamepad Template will apply to and work with every gamepad in existence. The Template only applies to and works with recognized gamepads that have controller definitions. There is no possible way to create a system that can automatically recognize and map all gamepads, steering wheels, flight controllers, or any other type of device because the required information to do this simply does not exist in the USB or HID data provided by the device. Only devices that have controller definitions can work with the Template system.
Awesome, thanks! I did read your note about how the gamepad template doesn't cover unknown controllers. I'm still sure it would be possible to make unknown controllers do *something* by default without each rewired user specifying mappings for "unknown controller".
For example, Unknown controller Axis 1 could automatically be set to whatever the user defines on the default gamepad template as the action for "Left Stick Y". Then, in many cases, newly made controllers that use "standard" axis mappings would "just work" by default.
Not trying to criticize- this is an amazing product you have built and I'm very happy to create an unknown controller map and already have, in fact. Jut offering a potential usability feature for newbies.
First of all: thank you very much for Rewired! I just started diving into it and it simplifies so many things!
I have a question about the PlayerMouse for which I couldn't find any "how to's" or other questions / FAQs:
When I create a PlayerMouse via scripting, as described here http://guavaman.com/projects/rewired/docs/PlayerControllers.html#player-mouse the PlayerMouse movement is hooked up as expected (subscribed to the ScreenPositionChangedEvent), but somehow I can't interact with the Unity UI (for example no hover / click on Unity UI buttons) when using the keyboard or a controller as input source. When I use Rewired.Components.PlayerMouse on a GameObject in the scene and add it to the Rewired Standalone Input Module (as done in the 'PlayerMouseUnityUI' example scene) it works as expected, also with keyboard or a controller.
I'm currently guessing I'd have to add the PlayerMouse I created via script to the Rewired Standalone Input Module, but the PlayerMice list is a list of Rewired.Components.PlayerMouse, so I can't simply add it there. What would be the correct way to add the PlayerMouse created via script to the Rewired Standalone Input Module? Or if that's not needed (if that's already done through the PlayerMouse.Factory), what am I doing wrong that the Unity UI interaction does not work as expected?
If I need to provide more information or something is unclear, please let me know!
Thanks in advance!
What you are suggesting is that Rewired assume everything is a gamepad. This isn't how Rewired is intended to work. It is designed to support all controller types equally. It also would introduce a number of problems:
Only Controllers that are explicitly supported by a Controller Template can implement the Controller Template. To make it do what you want, all Unknown Controllers must implement the Gamepad Template. This would be wrong because there is no data available about the elements on the Unknown Controller. The Gamepad Template would have to make incorrect assumptions about which elements are which. Then the user would be able to access those elements via the Gamepad Template elements such as GamepadTemplate.leftTrigger which is very unlikely to be aligned to the left trigger on the device if it even has one. "Left Stick" would be created out of Axis 0 and Axis 1. If the user is using a racing wheel, the Left Stick would likely end up being a combination of the wheel and one of the pedal values. Anything that relies on the Controller Template system to do something like display a Gamepad Template-based UI or save/load Controller Maps based on this template would completely break. Doing this would be a corruption of the Controller Template system and cause far more problems than it solves.
The reason the Unknown Controller definition even exists is so you can define a blanket default based on your own needs, whatever those may be. That may or may not be a gamepad. It's up to the developer. Rewired is designed to support every possible type of controller from the very foundation of its design and not to make assumptions that the user will be using a gamepad.
Player Mouse has no relation Unity UI. It can be used for literally any purpose you want. There is nothing built into the system that assumes you are going to use it for Unity UI. All Unity UI support in Rewired is handled through the Rewired Standalone Input Module.
You cannot add a non-component based PlayerMouse to the playerMice list. That only exists for assigning them in the inspector and they must be Components to do that. Look at the other methods in the class. Your IDE should show you them. Just start typing .mouse.
public IMouseInputSource GetMouseInputSource(int playerId, int mouseIndex);
public void RemoveMouseInputSource(IMouseInputSource source);
public void AddMouseInputSource(IMouseInputSource source);
public int GetMouseInputSourceCount(int playerId);
You could also create your PlayerMouse using the Component and instantiate it from a Prefab and add it to the list instead.
Thank you so much! Sorry for the basic question.
@jonas_gbanga see the edit I made to the post at the end just after you pressed "Like".
I am having an issue with your Joystick sensitivity from the "Sensitivity" option in the control mapper prefab.
Currently I'm moving a crosshair with the right analogue stick by the following:
crosshairPosX = PlayerInput.GetAxis("AimHorizontal") *Screen.width + Screen.width/2;
crosshairPosY = PlayerInput.GetAxis("AimVertical") *Screen.height + Screen.height/2;
crossHairIcon.position = new Vector2(crosshairPosX ,crosshairPosY);
This works great if I leave the Joystick sensitivity at 1. However, if I want the Crosshair movement to be slower (less twitchy) lowering the Sensitivity below 1 reduces its travel distance to the edges of the screen.
Is there a setting I can change or code I can modify that will still allow me to move the crosshair to the screen limits but in a slower manner?
InputBehavior.joystickAxisSensitivity is nothing but a straight multiplier that is applied to all Joystick axes. The value is then clamped -1 to +1. You are applying a straight multiplier to the Absolute joystick axis value which ranges from -1 to +1. By setting Joystick Axis Sensitivity to < 1, you are processing the value into a value that does ever reach 1.0 and therefore cannot be used as an absolute screen position if you want it to reach the edges of the screen. Joystick being Absolute coordinate mode axes return this value every frame. You are using this Absolute coordinate mode value directly as a viewport position which is a non-standard usage of a joystick axis value. Control Mapper's InputBehavior-based blanket Joystick Axis Sensitivity multiplier is not going to work for your use case.
You have two options:
1. Process the Action value yourself applying your own curve to it.
2. Calibrate the Joystick Axis and use a pow or curve for sensitivity.
Neither option is supported by Control Mapper.
So--it turns out, making cool vibration patterns is much harder than I thought. Does anyone have any good example code of vibration for various effects? It would be cool if maybe we started maintaining a gist collection or something of code snippets of nice vibration patterns that work on various platforms (2 motor stuff for most platforms, 4 motor stuff for others, etc.)
It appears 2019.1.0b7 has resolved the Selectable API issues on import
Not exactly. They changed the Selectables.allSelectables back to a List<Selectable> as it was before, deprecated it, and added Selectables.allSelectablesArray and Selectables.GetAllSelectablesNoAlloc. The code is still going to have to be changed to avoid a warning from using the deprecated property.
Yeah, I wish I had paid attention / remembered that Rewired sticks with stable releases before I updated my project. Good thing it was a pretty easy fix on my end.
Is there any way to remove the warning when using Rewired with Unity 2019? Turning off warnings in the log settings does not suppress it.
I was optimizing my UI Menus the other day and deleted some of the Graphics Raycaster Components that are not needed as they will never be clicked on. (Example. The loading menu in the first scene.) Well I think doing that somehow has disabled mouse input for many of my games users. Some of them claim that the touch screen on a laptop will work (also keyboard works) but a USB connected mouse will NOT work. So it must be something to do with the touchscreen turning the mouse input off.
Where can I make sure that this is not happening? I do not want the mouse to ever quit working. lol.
A couple of months ago, I built a nice system based on the Rewired."Last controller used Variable" that handles ALL the switching of the players inputs automatically so they can switch from a XBOX controller back to a mouse and keyboard easily.
What should I look at first? As the ONLY thing I changed last update to cause this is the Graphic Raycasters and UI Stuff. Nothing with Rewired settings.
Could I have deleted a touchscreen component somewhere that is now getting auto-generated?
I also made sure that the correct default mappings are set to load at default. (it has worked just fine for months on many builds before i messed with the menus and screwed it up.)
Thanks for any help or advice! This is killing me.
PC Standalone Game
New users with no saved game files report no mouse input but keyboard works.
Rewired Standalone Input Module inspector settings:
This is the only system in Rewired that interacts with Unity UI. (Touch Controls and Control Mapper both make use of the Rewired Standalone Input Module.)
Otherwise, use Debug Information to find out what's happening:
There is always the way to figure out what's wrong because it will show you every single thing in the Rewired system, live, in real-time. Use it to determine where the failure is by testing from the lowest level (Controller) up to the highest level (Player). If there are no issues here, then your problem is outside the Rewired system and somewhere above it in the UI system after the events have been sent and it is out of Rewired's hands.
Ok Thanks very much. Ill get on it.
I just found the post on the website about a prefab that I can drop into the scene and get all the debug values in generic simple UI? Is that in the newest build still? I didnt find it in the editor tools anymore on the newest version.
That has been there for several years. Look at the section Prefab Method in the list I posted:
I have a weird problem with some key combinations in Rewired. Sometimes when I unpause the game using Ctrl-Shift-P, I seem to trigger an action tied to a similar but different key combination (such as Ctrl-Shift-T or Ctrl-Shift-M). I've confirmed that I'm not actually pressing T nor M in these situations.
I'd try to debug this myself, but unfortunately the classes responsible for this are in a DLL.
The way you would debug this is using Debug Information:
Look at the live values of the Actions in the Player.
See what is getting activated.
Look for Controller Maps in your Player that bind the keys that are activating the Action. There may be bindings active that you are not aware.
Isn't that a really old Rewired version 18.104.22.168 ...the latest release of Rewired is 22.214.171.124. That is close to 50+ Rewired updates since that version. Or is that a typo in Rewired version?
Good catch. 126.96.36.199 was released on 12/21/2016.
Wow that is really old. I stopped counting when I hit 50 Rewired updates since that version. Maybe there are 100 Rewired updates since that version.
Does Rewired support Mouse and Keyboard for Xbox One? If so, my assumption is it will recognize those devices the same way it recognizes mouse and keyboard on a pc, correct?
This link contains all the information about libraries used on all platforms:
If UnityEngine.Input supports mouse and keyboard on Xbox One, Rewired will. Rewired does not have a native library on Xbox One. It uses UnityEngine.Input and the special Xbox One input classes provided by Unity on that platform.
According to this post, Unity 2019.1 added support for them on Xbox One:
Alright, I have been trying and trying to modify some of the configuration variables in Reinput (specifically the "use xInput" bool since there are cases in my game where someone may want to use it but it needs to be off by default.
After changing one of these variables, ReInput resets. So that's fine, I understand references are broken and everything, but I have tried everything - deleting and recreating objects that have references to Rewired objects, reloading the scene, loading other scenes. For whatever reason I just cannot get around this error:
"Rewired: You are attemping to access an object that was created by a previous session or different instance of Rewired and is no longer valid. When Rewired is reset or the Rewired Input Manager is disabled or destroyed, all old object references become invalid and can no longer be used. If you deinitialize Rewired, you cannot use locally stored Rewired objects obtained prior to deinitialization and you must get new objects from the Rewired API."
Also fun fact: If you change one of these config variables and load a new scene, the Unity editor completely freezes. But that's besides the point.
Does anyone have experience resetting ReInput and know what I'm missing? I have been going through the docs hard but all I can find are various takes on this sentence like Guavaman has said several times here: "Be aware that calling ReInput.Reset() will reset everything in Rewired as described in the API reference. This includes invalidating all stored Player, Joystick, or any other Rewired objects. Controller assignments will also be lost."
Would love any help anyone can offer!
That error can only possibly ever be reported when you are keeping a reference around to an old object that the previous session of Rewired created. Every single class-based object in the Rewired API stores an id in it from the instance of the Rewired Input Manager that created it. When you try to access some function or property on the object, it checks the stored id vs the current session id of the Rewired system. If it doesn't match, it means the object is outdated, wasn't created by the current Rewired instance, and cannot be used. You cannot possibly be getting this error if you are not using an old object instance that was created by a previous Rewired session.
Finding the problem old object reference is easy. Look at the stack trace.
There is no reason that should ever happen. Changing a variable that resets Rewired calls the exact same shutdown and restart methods that pressing Play or stopping it in the editor does. There is no interaction with scene loading and no difference between the two processes. I will test this again, but there is no code path that should have any effect on loading a new scene in the Unity editor.
If you are loading a new scene that has another Rewired Input Manager in it, or if the Rewired Input Manager does not have "Don't Destroy on Load" checked, other things must happen such as deactivation of the overlapping Rewired Input Manager or shutting down of the current one (depending on the case), which could cause your scripts to throw exceptions, etc. if Rewired is being destroyed and they're depending on it to be initialized.
I can't reproduce any issue in testing in Unity 2018.1.0f1 using Application.LoadLevel, SceneManagement.SceneManager.LoadScene, or SceneManagement.SceneManager.LoadSceneAsync after changing configuration settings.
I would need a lot more information about the exact setup to do further testing.
Level loading system being used
What setting is being changed
Is Rewired running in Edit mode?
Settings in the Rewired Input Manager and in the inspector.
Thank you for both replies! Turns out I had some sliders on my screen that were separately setting up new objects that used Rewired! Doh!
Also I can confirm I'm still getting the Unity freeze issue every time I load a scene immediately after successfully changing the "use xInput" variable.
Unity Version 2018.3.2
Rewired version 188.8.131.52.U2018
Edit: Nix that! I'm a dummy again. I was accidentally calling the function that reloads the scene after changing the variable every time I opened the scene! Infinite loop I created.. no need to check, thanks!
Really apologize on this. It turns out I was creating an infinite loop loading scenes back and forth. Thank you so much for your quick responses. Loving your product; it's making my 8-player game way easier to get working right.
@hockenmaier Glad you were able to work out all the issues.
i searched the topic to see if this sort of question has been posted, but i didn't find any, so excuse me if i missed it by accident.
I want to remap the buttons with Playmaker and i see there's Rewired Action Element Map Get Keyboard Key Code, but there's no Rewired Action Element Map Set Keyboard Key Code. Is there something i'm missing or i should use another action for that?
Template you made for controls mapping is really cool, but i've already got my own.
The remapping and conflict checking APIs are not available through PlayMaker Actions. The API is too complex for PlayMaker and is not supported. You can only access these parts of the API through scripting.
Thanks for the answer, i'll check it out
The recommended way to handle controller remapping is through Input Mapper:
Hello, sorry if that question was already asked or if there is an official form to request it:
I saw that a Corgi Engine integration was made for Rewired. The creator released a few months ago an asset called "Top Down Engine"
Would there be by any chance a way to get an integration for that asset?
If not I'll use the input override method, but it'd be nice to have natively of course
I don't have any plans on making an integration for Top Down Engine.
Hi, just wondering, what's the difference between Mouse and PlayerMouse class, they both have the screenPosition, but is one recommended over another?
(For example, if a game supports either mouse or controller, which is the more correct way to read the current cursor position, regardless of input device? Also, since we already have Player class, why isn't it exposed there?)
(EDIT: ok it looks like Player.controllers is the way to go.)
I got a really strange issue with the gamepad. Horizontal input and buttons i have mapped for firing work fine, but vertical input does not work at all.
I tried resetting inputs from the unity project setting and reinstalling rewired, but the problem persists. I tried using the system player as well as Player 1 with the same setting, but it's still the same.
So i tried some debugging. Here's what it says:
Axis 0 is horizontal and receives input from -1 to 1
Axis 4 is vertical and receives input from -1 to 1
Axis three is i don't know what, it's always stuck to -0.991
Here is my movement setup (i use playmaker)
X clearly shows horizontal axis input, but y stays at 0.0 when i press up or down. Keyboard controls work great and the inputs are clearly visible for both axes in the variables.
I tested the joypad in other games, it works (it's brand new).
There are the input manager setting:
I also tried some rewired actions to see if i get some axis input, but it's all 0.