Search Unity

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,627
    Rewired already uses HID system events to trigger re-polling of the device list. The problem here is XInput says the device is still connected for 2-3 seconds. XInput is the only thing that can give you information about XInput devices.

    There's no possible way to associate a HID device with an XInput device (without making an association manually by polling the user for input and watching which HID device responds to their button press which is prone to failing should XInput device ids change for whatever reason). XInput is its own system and gives literally no information about the device except its XInput index and a very generic controller type enumeration. There's no way to know that a particular HID disconnect belonged to an XInput device. (This is the same reason for this.)

    I do not believe there is any possible workaround for this issue. Microsoft needs to fix the problem.
     
    FriedelDev likes this.
  2. Mystgun

    Mystgun

    Joined:
    Jun 18, 2016
    Posts:
    7
    @guavaman I try searching for a solution but I could not find it. I just want to know what type of joystick the player is using. the system is simple from the last controller use I want to know if is an Xbox type controller or a DualShock type of controller so I can change my interface with the correct sprites.
     
    Last edited: Oct 17, 2020
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
  4. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Hello,

    Where do I make sure the "Settings" text remains to auto size for me SettingAndMapCategoriesGroup -> SettingsGroup -> Label
    In the prefab its set to auto size (max 20) but once its run the control mapper updates it

    Also, same for the Actions text of the buttons and the keyboard map name as well, I'd like to change things like auto size, wrapping disabled etc

    Thank you
     

    Attached Files:

    Last edited: Oct 24, 2020
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Use the Theme to set text settings:
    https://guavaman.com/projects/rewired/docs/ControlMapper.html#theming

    If the theme does not provide an option for setting some text property, it's not customizable.
     
  6. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    I am using my theme, but auto size to max 79 by default on spawn via control mapper is unrealistic

    In a previous version I did not have this issue not sure whats changed, I'd modify the code myself in DrawSettingsGroup if i knew how...
     

    Attached Files:

  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    The size of the text is is based on your settings for text in the theme and the value on the component. The default size on the component is 8 min, 18 max. Any change in this value on Play means you've changed Text settings in the theme that is causing it to scale. Theme -> Text Settings -> Size Multiplier will multiply both the min and max values of all themed text. This multiplier is applied to the initial value of Min/Max that was set on the component before Play mode. If you have modified this value on the component to be something large, then your Text Settings -> Size is telling it to multiply that value by a number greater than 1, you'll get the result you are describing. Change the value you have set on the component to be some value that when multiplied by Size Multiplier equals the final value you want. If you are modifying a prefab, ensure your prefab instance does not have an override that's changing the value you expect to see.
     
    Last edited: Oct 25, 2020
  8. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Thank you,

    I changed the multipliers to 1 for all texts. There were no changes on the UI which is good, except the settings label was still off, then to test and find out which one it is for sure i changed the line spacing for the theme text settings and it did apply it on it.

    It seems if i don't auto size it and i leave it at 10 (or any other #), it will be 36, if i auto size it it goes to 72 (min 18 max 72), yet all the other texts seem fine.

    For now leaving it at no auto size and it going to 36 is ok

    Perhaps when I moved it from my other project to this something happened and it broke that one part not sure

    Another test I did is i put the text multiplier to 0.3, at this point the settings text did get impacted however, all the other ones did too :)
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Revert the component on the prefab.

    I suspect this is some kind of serialized data corruption. Unity very frequently corrupts data in Control Mapper for some unknown reason. I get reports from people all the time that none of the prefabs are linked in the inspector when they install control mapper. It's nothing but a GameObject, but Unity's serialization system for some reason is broken when it comes to these particular objects. I have seen other inexplicable errors as well, but this isn't something I can fix because their serialization system is just supposed to work.

    You could also try removing the text component and adding it back. You will need to hook it back up to the Component field of the Themed Element component on the same GameObject and the Label field in the parent SettingsGroup's UI Group component.

    There is no code whatsoever that would change the size of the text if you have Size Multiplier set to 1. Here is the code. No other code modifies text size.

    Code (csharp):
    1. private void Apply(string themeClass, Text item) {
    2.             if(item == null) return;
    3.  
    4.             TextSettings settings;
    5.  
    6.             switch(themeClass) {
    7.                 case "button":
    8.                     settings = _buttonTextSettings;
    9.                     break;
    10.                 case "inputGridField":
    11.                     settings = _inputGridFieldTextSettings;
    12.                     break;
    13.                 default:
    14.                     settings = _textSettings;
    15.                     break;
    16.             }
    17.  
    18.             if(settings.font != null) item.font = settings.font;
    19.             item.color = settings.color;
    20.             item.lineSpacing = settings.lineSpacing;
    21.             if(settings.sizeMultiplier != 1.0f) {
    22.                 item.fontSize = (int)(item.fontSize * settings.sizeMultiplier);
    23. #if REWIRED_CONTROL_MAPPER_USE_TMPRO
    24.                 item.fontSizeMax = (int)(item.fontSizeMax * settings.sizeMultiplier);
    25.                 item.fontSizeMin = (int)(item.fontSizeMin * settings.sizeMultiplier);
    26. #else
    27.                 item.resizeTextMaxSize = (int)(item.resizeTextMaxSize * settings.sizeMultiplier);
    28.                 item.resizeTextMinSize = (int)(item.resizeTextMinSize * settings.sizeMultiplier);
    29. #endif
    30.             }
    31. #if REWIRED_CONTROL_MAPPER_USE_TMPRO
    32.             item.characterSpacing = settings.chracterSpacing;
    33.             item.wordSpacing = settings.wordSpacing;
    34. #endif
    35.             if(settings.style != FontStyleOverride.Default) {
    36.                 item.fontStyle = GetFontStyle(settings.style);
    37.             }
    38.         }
     
    Last edited: Oct 25, 2020
    zKici likes this.
  10. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Very odd indeed,

    Was not sure what revert component on prefab meant, so I tried removing the text component and adding it back to the group but that did not work either. What worked was deleting the text object completely and adding a new one, now it works as it should.

    Thank you for your help much appreciated
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    On the prefab instance:
    Click the gear icon in the upper right-corner of the component, select Modified Component -> Revert. If Modified Component is not displayed, the component is not modified.

    This serialization problem is becoming a huge deal. It's a big waste of my time and the users time to keep having to track down the infinite different manifestations of this stupid bug. I'm probably going to go re-save every prefab and object again in each version of Unity and have to maintain 10 separate branches of Control Mapper (regular and TMPro) for all the different versions of Unity because of this. There's no reason serialized objects from older versions of Unity shouldn't work in newer, but that's exactly what's happening...

    Is this the TMPro or regular version? I'm guessing TMPro.
     
    Last edited: Oct 25, 2020
  12. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    That is truly unfortunate that Unity cant get things right, causing developers and users a lot of headaches and wasted time indeed.

    I'm using TMPro
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Now that I recall, there are also problems like that that happened when the GameObject was saved with an older version of Text Mesh Pro. That's not going to be possible to solve with branching because each version of Unity may have any number of different versions of Text Mesh Pro. Based on my trial and errors in the past when I first added TMPro support, I found there's a lot going on under the hood with these TMPro GameObjects that isn't normal. They seem to have some capacity to store extra information that isn't exposed and causes problems when the version of TMPro is upgraded. I have also seen the TMPro component behave incorrectly reporting values through scripting that are not equal to the values displayed in the inspector, as if there are multiple values stored internally. I don't think there's any possible way I could fix this other than to resave the objects for all versions of TMPro in all versions of Unity and that's simply just not feasible. That's the reason I made Unity 2018.0 the base version that supported TMPro. Because I THOUGHT I found the base stable version of TMPro that would update correctly to newer versions. I was wrong.
     
  14. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Hopefully things get sorted out in the near future and help awesome developers such as yourself to keep releasing good content and updates =)
     
  15. iansnyder

    iansnyder

    Joined:
    Dec 22, 2012
    Posts:
    27
    Hey there, I'm a long time Rewired fan! Recently had to get things ready to save to various cloud platforms so I'm finally replacing UserDataStore_PlayerPrefs with customized storage and ran into a weird issue.

    I got the file saving out, and I just replaced calls to PlayerPrefs with a custom data container. I am saving and loading data, but Action Mappings are not sticking, while Sensitivity settings are.

    So for example, I run the game, go into the Control Mapper and change mouse and joystick sensitivity, as well as default key mappings. If I back in and out of the menu, those settings stay correct, even though I am saving and loading my custom data file on entering and exiting the Control Mapper. But once I stop the game and restart it, only the Sensitivity settings are saved. Looking at my saved data, it looks like Sensitivity is saved, but I don't see any changes to KeyCode mappings or anything.

    Making changes during gameplay, they are kept:
    upload_2020-10-28_20-45-1.png

    After stopping and hitting Play again, only Sensitivity settings carry over.
    upload_2020-10-28_20-46-1.png

    Any ideas on where I may be messing up? I've attached a .txt version of my Save Data. Really appreciate any help. Thanks so much!
     

    Attached Files:

  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    That can only mean either you're not saving the Controller Maps, you're not loading the Controller Maps into the Player, both, or the Controller Maps are being cleared by some other script after loading them. That would be in your code implementation of UserDataStore as this certainly works with the default UserDataStore_PlayerPrefs. Adding logging at the point Controller Maps are loaded to see exactly what is being loaded and into what Player and when should lead you to the cause.

    Use Debug Information to see what is loaded at runtime and don't rely on Control Mapper for this:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information

    I don't see any reason you should be loading your save data when opening Control Mapper. You should be loading it on Start and when a controller is assigned to a Player.
     
    Last edited: Oct 29, 2020
  17. iansnyder

    iansnyder

    Joined:
    Dec 22, 2012
    Posts:
    27
    I appreciate the detailed response -- I ended up just re-implementing it from a fresh copy of your UserDataStore_PlayerPrefs and it's working, I must've typo'd something when I was hacking at it last time :D I appreciate the heads-up on proper timing for loading data -- that makes sense, so I've made the change. Thanks again for Rewired, it's been a life-saver for supporting Windows and Xbox One simultaneously!
     
    guavaman likes this.
  18. ElasticSea

    ElasticSea

    Joined:
    Aug 10, 2016
    Posts:
    10
    Is it possible to have some action 'unbound' in the joystick map for example in the Rewired Editor? I want them to be blank by default (so no controller element is connected to that action) with the option that players can bind them in the game if they want.
     
    Last edited: Oct 30, 2020
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    No. Blank Action Element Maps are deleted upon loading of the Controller Maps from the Rewired Editor data.
     
    ElasticSea likes this.
  20. ElasticSea

    ElasticSea

    Joined:
    Aug 10, 2016
    Posts:
    10
    Ok, got it. Amazing asset, by the way, a pleasure to work with.
     
  21. whatnotory

    whatnotory

    Joined:
    Sep 21, 2017
    Posts:
    7
    Hi, apologies if this was covered elsewhere but I wasn't able to find anything:
    I think there might be an issue with the joystick-controller deviceInstanceGUID on OSX. (It seems to work fine on Windows)

    With Rewired 1.1.36.1.U2019 and 2 dualShock4s connected through usb in the Unity editor (2019.4.12f1) -- both DS4s return:
    HardwareTypeGuid: cd9718bf-a87a-44bc-8716-60a0def28a9f
    HardwareIdentifier: OSXInternalDriverWirelessController13562508
    DeviceInstanceGuid: c74884bd-835a-9310-49bc-8d58f4d3c5b7

    And in an OSX standalone build, the controllers also behave in the same way -- as if their deviceInstanceGUIDs are not unique.
    I tried connecting a Switch ProController -- which was assigned a unique deviceInstanceGUID.

    This was all tested on an iMac running Catalina (10.15). Additionally, I ran a test from a fresh Unity project, which also displayed the undesired behavior.

    In the Rewired documentation I read that support for deviceInstanceGUID does vary by platform, but I did have it working in OSX for an older version of my project: a standalone build running Rewired 1.1.30.0 and created with Unity 2018 lts (I believe specifically 2018.4.24f1).

    Any thoughts?

    Thanks
     
  22. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,048
    I created an action called unassigned. I have bound all the currently unassigned keys in my game to that action. When a player hits one of those keys I can detect it but how do I know specifically which key triggered the action?

    I want to highlight the specific key pressed on a virtual keyboard.
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Nothing has changed with device instance guid in years. These guids are generated based on whatever information I have available to me on the platform to uniquely identify a device and a hash is generated from that. Two devices having the exact same id means that the two devices are both returning the exact same information for the 8 criteria I use on OSX to attempt to create a unique identifier. If that's the case, there simply isn't a way to uniquely identify them.
     
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    ibyte likes this.
  25. whatnotory

    whatnotory

    Joined:
    Sep 21, 2017
    Posts:
    7
    Thanks -- is there anything that I might be able to do on my end that would wrangle out a unique deviceInstanceGUID from OSX or does it appear to no longer be working on any OSX system? I'm trying to use it for things like controller reconnect. (followup question: if deviceInstanceGUID no longer works for this function, is there some other strategy for controller reconnect that you'd recommend?)

    Since my post last night, I tested with a different set of dualShock4s on another OSX computer -- this time running Sierra (10.12) -- which displayed the same deviceInstanceGUID behavior.

    And, again, the behavior occurred even with a fresh Unity project.

    Thanks
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    No there is nothing you can possible to do change this. This is very low-level code on OSX and internal to Rewired's OSX DLL. I can't generate a unique identifier for the device unless there is some kind of unique information provided by the device or the OS about the device. One of the 8 criteria I use is the serial number of the device. Even that is identical among them. So no, I see no way to achieve this.

    The only reason this even exists is so you can identify a device uniquely and have that persist between runs of the application. If you only need to identify them uniquely during an application session, use the Controller.id. If you need to persist this between sessions, I see no possible way to do it. If there were a way to uniquely identify them, my deviceInstanceGuid would be working and could be used for this purpose. Nothing at the high-level (Rewired) can be used to uniquely identify them if it can't be done at the low level.
     
    Last edited: Oct 31, 2020
  27. whatnotory

    whatnotory

    Joined:
    Sep 21, 2017
    Posts:
    7
    Seems like Controller.id may be useful -- thanks

    I ran a couple more tests -- trying to limit some of the variables and also came across an issue for me in the new version of Rewired (1.1.36.1) with reconnecting controllers on MacOS.

    Starting with a fresh Unity project.
    Running in Editor (2019.4.12f1) on an iMac (Catalina) targeting MacOS.
    Rewired 1.1.30.0
    3 DS4s connected through usb. (and also mouse and keyboard)
    Diagnostics read through Rewired's "Debug Information".
    After enter Play mode:
    • works great -- each DS4 properly receives a unique deviceInstanceGuid
    • when a controller is unplugged and replugged -- both actions are detected successfully by Rewired
    • (of course there's a warning message about this version of Rewired not liking Unity 2019)

    And then a test with everything being the same but using Rewired 1.1.36.1
    After enter Play mode:
    • all DS4s have the same non-unique deviceInstanceGuid listed
    • unplugging 1 of the DS4s shows 2 controllers as having been disconnected. (started Play mode with 3 connected)
    • After plugging in the disconnected controller, "Debug Information" never shows the controllers as having been reconnected. (after exiting Play mode and then starting it again we do see all the controllers as connected)

    I'm not sure if the following is a path worth checking but somewhere is there an archive of older Rewired versions? -- so I can try some of the older versions that are still compatible with Unity 2019
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    All versions of Rewired are compatible with all versions of Unity. If you are getting an error message about using the Unity 2020 version of Rewired in Unity 2019, it is because of Unity Package Manager bug:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#wrong-rewired-version-installed

    Using the Unity 2020 version in Unity 2019 could cause problems because Rewired U2020 is built to Unity 2020 libraries, not Unity 2019.

    As far as I remember, nothing has changed at all on OSX that would have affected the unique identifier in years. I will look through my release notes and look at the code to see. But there is absolutely no way any new changes have been made that would cause the controllers to no longer re-connect. Something very wrong is happening and I have no idea what, but the OSX code has been almost entirely untouched for years. Do you happen to be using Unity as the input source and not Native?

    There is no public archive of old versions of Rewired.

    Edit:
    The only OSX change in the release notes since 1.1.30.0 are these:

    1.1.30.3:

    Bug Fixes:
    - OSX Native: Fixed bug causing joysticks created from HID devices with multiple logical sub devices to possibly shift around when another joystick device is connected or disconnected.

    1.1.30.2:

    Changes:
    - OSX Native: Added support for HID devices with multiple logical sub devices (some multi-port controller adapters including Mayflash GameCube contorller adapters).
     
    Last edited: Nov 1, 2020
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    @rossk

    I was suspicious of one line of code that was commented out in the current version. I checked and it was not commented out in 1.1.30.0:

    Code (csharp):
    1. _instanceGuid = Utils.MiscTools.CreateGuidHashSHA1(
    2.    manufacturer +
    3.    productName +
    4.    VendorId +
    5.    ProductId +
    6.    serialNumber +
    7.    Version.ToString() +
    8.    transport +
    9.    logicalDeviceIndex
    10.    //LocationId // This can't be used. It would make it only work if plugged into the same USB port
    11. );
    LocationId used to be used in the instance guid, but I removed that at some point because of what it says in the comment. That made it appear to work in 1.1.30.0, but it actually is not working even though it appears to. All it was telling you is that the controller is connected to a specific USB port. It cannot uniquely identify a controller, and does not achieve the goal of the instance guid function of uniquely identifying a specific controller, only the port its connected to.
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    @rossk Well that's the explanation for everything. Even Controller.id breaks down because there's no way to know one controller from the next, so when a controller is re-connected, the instance guid is used to figure out which Controller.id it should be assinged to so the previous controller object can be used. Without any way to positively identify the controller from one plug to the next, even that fails because all controllers are being identified as the same controller. Tying controller identification to the USB port like it does in 1.1.30.0 is wrong because if you move the controller to a different port, even if only one controller is attached, it will be detected as a new controller and will not reuse the previous Controller.id and cannot be re-assigned to the previously owning Player. I don't have a solution.

    This issue would only happen with identical devices that do not provide a unique serial number.
     
    Last edited: Nov 1, 2020
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    @rossk The best I can do is implement both a location id check and instance guid check when trying to identify which controllers are still connected to keep them aligned correctly. This should solve the problem where the controller do not reappear on re-connect, but it won't make deviceInstanceGuid unique for each device. It also will not make it able to identify controllers correctly if they are all plugged in, then all unplugged, and then all replugged into different ports.
     
  32. Xrsftw

    Xrsftw

    Joined:
    Jan 27, 2018
    Posts:
    2
    Is the new PS5 controller with haptic feedback features are going to be supported in the future?
     
  33. funselektor

    funselektor

    Joined:
    Oct 11, 2013
    Posts:
    105
    Hi Guavaman. We have a racing game w/ remappable controls and users of Fanatec wheels are reporting that they can't remap them. On the supported controllers for Rewired it only has support for the Fanatec Porsche Wheels, is there any way to add support for more?

    And the same goes for this Thrustmaster wheel: http://www.thrustmaster.com/products/t-gt
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    There is no reason any controller can't be remapped. Rewired remapping system was designed to support any kind of device. If the device simply is not working in any way, then it's not a problem of support for that controller. That would mean the controller is not sending HID reports and probably has something to do with the mode the device is in or drivers.

    Controllers listed on the Supported Controllers page only means that Rewired comes metadata for mapping of the controller element indices on various platforms, provides element names, and provides a way you can pre-map your Actions to the device in the editor. That's all it does. A Controller definition cannot make a device that does not work through standard HID means work.
     
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    I'm not going to promise anything about the PS5 controller. The PS4 controller vibration, gyro, light support was only possible because of extensive reverse-engineering of the PS4 controller's protocol that people did to be able to recreate the protocol the PS4 uses so these features could be used on Windows. After that, I have to write a sort of a driver for the device using that information. Until all the technical details are available, I cannot possibly support those features on desktop platforms.
     
    Last edited: Nov 2, 2020
  36. AaronKB

    AaronKB

    Joined:
    Aug 16, 2019
    Posts:
    27
    Hi there. I'm looking to add support for Switch to our game and with our current controller setup we can have one configuration for all controllers using the GamePad Template. However, on Switch and A+B buttons are typically swapped and I was wondering if there's an easy way to make all the Switch controllers just swap those two buttons without having to go and make individual JoyStick Maps by hand for each joystick Switch supports?

    I've also noticed that touchscreen events are not positioned correctly for UI button presses. On iOS our touches work perfectly, but on Switch the seem offset, and sometimes the offset is not consistent from button to button. Could this be something Rewired related?
    Thanks
     
    Last edited: Nov 2, 2020
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Much concerning Nintendo Switch is covered by NDA and therefore I cannot provide support for it on this public forum. Contact me through the support form on the website.

    Your first question is answered in the documentation that comes with the Nintendo Switch plugin.

    Your second question, there is no reason whatsoever why Nintendo Switch would behave any differently when it comes to Unity UI. The code for the UI touch controls is completely platform-agnostic and uses Unity's platform-agnostic UI system for all functionality. I cannot imagine any reason for it to be offset other than some kind of Unity bug or something in your UI Canvas hierarchy. I have not specifically tested this on the Switch because Unity UI is supposed to be entirely platform-agnostic and I should not have to detect the platform and do a single thing differently.
     
  38. funselektor

    funselektor

    Joined:
    Oct 11, 2013
    Posts:
    105
    This is good news, I will ask them for some more info thanks!
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    I just tested touch controls on Nintendo Switch and there is no offset issue in any of my examples.
     
  40. AaronKB

    AaronKB

    Joined:
    Aug 16, 2019
    Posts:
    27
    Thanks.

    I went and found the docs (I couldn't find anything on the site, which would be handy). Am I right in thinking that I should create a Layout Manager ruleset and add separate rules for each Switch controller type (Pro, Joy Con Dual, Left, Right etc) that chooses my switch layout, and then a final one for default layout? If so, then the Hardware Type (Which is the only option that allows controller type selection) seems to require a Hardware Identifier. Does it? All I'm trying to do is say "Use layout X for any Nintendo controllers"

    Looking through the docs I see it suggests using a Map Enabler as well but doesn't the Layout Manager take care of ensuring what layout is in effect based on the rules? I think there's something I'm not understanding here. I have added a Switch Layout under joystick layours, added a Layer Manager Rule that chooses that layout on conditions (Which I'M not sure is right as mentioned above) and I have added Joystick Maps under GamePad Template, for both of our categories and for Switch Layout. Does this sound correct?


    Additionally, it would be really handy if I could copy an entire map and paste it elsewhere. What I found I wanted to do was copy our mappings that were under, say GamePad Template to Nintendo Switch Pro Controller or somewhere else.

    Regarding the other issue I will continue to investigate.
     
    Last edited: Nov 4, 2020
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    You do not have to make separate rules or maps for every controller type.

    Make one Gamepad Template map that is in the Nintendo Layout and swap A and B. Use a Layout Manager rule set for normal platforms and one for Switch. Write a script to enable the appropriate one Layout the current platform.

    The documentation is included in the plugin and the instructions text file that is included in the zip tells you the location of the documentation. Everything in the documentation is covered by NDA and cannot be put on the public documentation website. I have no system for logging in users in order to view NDA restricted documents.

    Copy and pasting maps across controllers is not feasible if you understand how the system works internally. No controller map has any relation to any other controller map. Each has its own unique list of elements and those elements may not even be in the same order or even the same type (axis vs button). There are also a lot of issues with doing the same for templates. I've explored this before and dropped the idea because it was fraught with issues.
     
    Last edited: Nov 4, 2020
  42. AaronKB

    AaronKB

    Joined:
    Aug 16, 2019
    Posts:
    27
    Ahh, so I still need to script something? The docs suggest I could use script OR the layout manager so I was assuming I could do everything in the UI but I couldn't figure out how to swap.

    Also, am I right in thinking I shouldn't need to use Map Enabler rules?

    Thanks for your help.
     
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    The docs suggest you could use the _example_ script that is provided or use Layout Manager. Using Layout Manager should not imply it's a completely drag-and-drop process. Changing between layouts always requires scripting/ There's no way to do that without scripting. You can see how Layout Manager works by reading the Layout Manager documentation.

    Map Enabler serves a completely different purpose. If you want to keep certain maps that are currently loaded in the Player disabled and others enabled based on some kind of state change, use it.

    I don't remember off the top of my head whether or not the Controller Maps loaded by Layout Manager will be automatically enabled or not. It is likely if they are replacing an existing Controller Map in the same Map Category in the Player, they will inherit the enabled state of the previous Controller Map because that is generally how loading controller maps into Players works. If that doesn't happen, use Map Enabler to enable that category. Assuming you're never enabling/disabling controller maps otherwise, simply enable all with a rule.
     
    Last edited: Nov 4, 2020
  44. AaronKB

    AaronKB

    Joined:
    Aug 16, 2019
    Posts:
    27

    Thanks.

    I've managed to make some maps and layouts and if in the player settings under Controller Map Helpers I set up my rulesets, enabling switch by default and disabling the default one, I get the buttons switching. However in my script, when I do this it is not coming into effect. Maybe I am changing these things too early in the start up process, or changing the wrong thing. This is what I have, called in Awake in a GameObject that is a child of the object holding Rewired Standalone Input Module. I tried in Start as well but no luck.

    Code (CSharp):
    1.        
    2.         var player = ReInput.players.GetPlayer(RewiredConsts.Player.DV_Player);
    3.         var ruleSets = player.controllers.maps.layoutManager.ruleSets;
    4.         var defaultRuleset = ruleSets[RewiredConsts.LayoutManagerRuleSet.Joystick_Default_RS];
    5.         var switchRuleset = ruleSets[RewiredConsts.LayoutManagerRuleSet.Joystick_Switch_RS];
    6.  
    7.         defaultRuleset.enabled = false;
    8.         switchRuleset.enabled = true;
    9.  
    10.         player.controllers.maps.layoutManager.Apply();
    11.  
     
    Last edited: Nov 4, 2020
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    You are trying to use the Rule Set id as an index. See this about IDs in Rewired: https://guavaman.com/projects/rewired/docs/BasicUsage.html

    You must use the Tag to find the rule set you want to enable or disable. This is shown in the examples in the Layout Manager documentation: https://guavaman.com/projects/rewired/docs/LayoutManager.html#enabling-disabling-rule-sets

    You cannot use the Rule Set Id to find an instanced Rule Set at runtime. The Id shown in the editor and exported in constants is exclusively for identifying a Rule Set in the Rewired Input Manager data set in order to instantiate it. Once it's instantiated, it no longer has any relation to the Rule Set it came from or the editor data id.
     
  46. AaronKB

    AaronKB

    Joined:
    Aug 16, 2019
    Posts:
    27
    I was wondering about this myself after looking at the Debug Info in the inspector just now and came to post I had found the reason it wasn't working.

    Again, thanks very much for all your help. Things seem to be working well now (In the editor at least).
    Aaron
     
  47. BigGreenPillow

    BigGreenPillow

    Joined:
    Dec 2, 2013
    Posts:
    26
    Hi, I did a search in this thread and saw that you were recommending to not use the Package Manager to import Rewired to the project but on Unity 2020.1.10f1 I don't think I have a choice, even trying to open it from the Asset Store it stills load the Package Manager page, I'm having a problem here that on my machine it works fine after importing from the Package Manager but when I commit it on git to another machine Unity somehow stops understanding the namespace and it keeps giving exceptions like this one: "Assets\Rewired\Internal\Scripts\InputManager.cs(71,19): error CS0234: The type or namespace name 'Platforms' does not exist in the namespace 'Rewired' (are you missing an assembly reference?)"

    Do you have any idea how I can get this to work or what could be going wrong? I saw that today we had a new update for the plugin but this is still happening even after reimporting the updated version.

    Thanks!
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    See this:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#wrong-rewired-version-installed

    This problem only applies to Unity 2019, not Unity 2020.

    That error doesn't have anything to do with the fact you're using Rewired 2020. An error like that is a compiler error. It's telling you that the script cannot find the assembly that contains the Rewired.Platforms namespace. That means Rewired_Core.dll is not being linked. Unity is completely responsible for linking assemblies. This isn't a Rewired issue, it's a Unity issue.

    Unity is either not importing Rewired_Core.dll or it is not linking the assembly in the assembly that is being compiled from the scripts. Unity will block a DLL from loading permanently if there are certain kinds of errors until you manually reload that assembly. If the DLL's metadata is broken and the current build platform does not include the DLL, that would also do it. But the most common reason for this is ASMDEF files. If you're using these in your project, unless you set them up very explicitly and correctly, things are going to break.

    You will also have problems if you have multiple copies of Rewired in your project.
     
    Last edited: Nov 6, 2020
    boysenberry likes this.
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Rewired 1.1.37.0 is on the Unity Asset Store.

    1.1.37.0:

    Changes:
    - Windows Standalone, Raw Input, Use XInput disabled: Implemented workaround for Steam not creating device notifications when creating or removing virtual controllers so controller changes can be detected correctly.
    - Export constants variable, class, and namespace sanitization now uses a blacklist instead of a whitelist so unicode characters such as non-English characters are no longer filtered out. (May lead to compiler errors if certain invalid characters are used in identifier strings.)
    - Bolt integration: Added PreserveAttribute to all classes to prevent Unity from stripping the classes on certain platforms.

    API Changes:
    - Added Platforms.PS4.PS4ControllerExtension.deviceHandle property.

    Bug Fixes:
    - Action Element Maps that bind to an invalid controller element are filtered out when loading Joystick Maps in Players.
    - Control Mapper: Null Reference Exception is no longer thrown when looking up a controller element name for an Action Element Map that maps to an invalid controller element.
    - MacOS Standalone, Native: When using multiple identical controllers that do not provide enough identifying information to differentiate the controller from the others and one controller is disconnected and reconnected, it will now be detected and re-appear in the Joysticks list.
    - Fixed bug in ComponentControls.TouchPad.pressStartDelay property causing value to always be set to float.MaxValue if set from scripting.
     
    zKici likes this.
  50. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Thanks for this update. That steam workaround is great!