Search Unity

Rewired - Advanced Input for Unity

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

  1. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    I'm running Rewired 1.1.12.2 on Unity 2017.1.1f1.
    I'm having some issues involving using the keyboard shift key with numpad keys simultaneously.

    One issue is: GetButton (actionId) for shift key reports false during the frames when a keyboard numberpad key is being held down.

    Repro:
    • Assign a shift key to an action
    In Playmode:
    • Ensure NumLock is enabled on keyboard (it only seems to happen when numlock is enabled)
    • Press and hold the shift key key down
    • Press and hold a key on the numberpad on the keyboard
    • Note rewired GetButton(<action assigned to shift key>) will report the shift key is NOT being held down when a numpad key is pressed. Once the numpad key is released, rewired will then report GetButton() is true for shift key
    I tried on two different keyboards with the same results. Is this an issue with a setting or rewired? Or is this just a limitation of a keyboard?
    I have a repro if you need it.

    settings.png
     
    Last edited: Aug 14, 2018
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    It's not an issue with Rewired. It's the keyboard and how probably all keyboards work by design. If you were to watch the key codes being returned, you would see it change from Shift to Left Arrow when you press Shift + 4 with Num Lock enabled. This is so you can access the various functions on the number pad without disabling Num Lock. If you open a text editor and do the same thing, you'll see the cursor move to the left.
     
    Last edited: Aug 14, 2018
  3. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    After further testing that issue only seems to happen with the left shift key.
    For the right shift key, a completely different issue occurs.
    If the right shift key is pressed and held down, and a number pad key is pressed, then release all keys, Rewired GetButton will continue to report that the right shift key is being pressed, even though no keyboard buttons are currently being pressed. I tried creating a build for Windows and issue occurs in build. In the editor, it will continue to report the right shift key GetButton as true until the mouse is clicked on certain areas in the Editor, such as the hierarchy window. Then Rewired will start reporting GetButton as false.
    I tried with both an Insignia USB keyboard and Lenovo USB keyboard.
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Again, this is the keyboard at fault as well as possibly the Windows API. Rewired isn't the only victim of this problem. Unity's input system does it as well. I was testing all of this last night seeing keys get stuck on on both systems, oddly not always the same keys. (Rewired uses the Raw Input API, Unity uses Rewired will get a Left Shift press event when you RELEASE the 4 key while pressing Right Shift + Num Pad 4. The Left Shift Down event is sent, but Left Shift Up is never sent by Windows. Similarly, Unity will stick Left Arrow on forever if you do the following: Hold Right Shift, press 4 on the keypad with num lock enabled, then release Shift before releasing 4. The reason for these problems is that Windows doesn't use a polling-based API for keyboards. It's events. So if Windows doesn't send an Up event, there's no way to know the key was released. The keyboard or Windows isn't sending Up events for these number keys + L/R shift.

    You can see this in action for yourself with a tiny bit of code:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class KeyCodeTester : MonoBehaviour {
    5.  
    6.     private int[] values;
    7.     private string[] names;
    8.  
    9.     void Awake () {
    10.         values = (int[])System.Enum.GetValues(typeof(KeyCode));
    11.         names = System.Enum.GetNames(typeof(KeyCode));
    12.     }
    13.  
    14.     void Update () {
    15.         for(int i = 0; i < values.Length; i++) {
    16.             if(Input.GetKey((KeyCode)values[i])) Debug.Log(Time.time + ": " + names[i]);
    17.         }
    18.     }
    19. }
    Unity uses WM_KEYDOWN / UP events, whereas Rewired uses Raw Input events which could explain the slight differences between the two.
     
    Last edited: Aug 14, 2018
    ArachnidAnimal likes this.
  5. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    What would you recommend to avoid the player encountering this issue? Prevent user assigning shift keys to the input or prevent user assigning numpad keys to input?
     
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    I really don't have a recommendation.

    Preventing shift keys from being used for input is definitely not standard. Most games map something like Run to shift.

    I don't think this is really much of an issue. This isn't a new problem obviously, certainly does not affect only Rewired, and I've never heard of it before even after all these years and thousands of developers using Rewired. The only thing I can think of is to put something in your documentation that says to disable Num Lock.
     
    Last edited: Aug 14, 2018
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    @TTTTTa after a bunch of hacking, I decided that it would probably be okay to simply ignore all these "virtual" key up/down events that are causing this problem. Basically, I have to make shift simply be always active as long as no actual hardware break command is sent for that Shift key, ignoring all other events. This has side effects in that these special Shift + number pad keys no longer block the Shift button from being active, which is what you want, but there could be other side effects. This is a change from the existing system and different from how Unity works. Other keys that used to block Shift when pressed also now do not such as Insert and Delete. However, the problem of Shift + Num Pad keys getting stuck when the Shift key is released before the key on the keypad is impossible to fix because no up event is ever sent by the OS for these. It is also impossible to detect Keypad 4 when Shift is held while Keypad 4 is pressed with Num Lock on because no event is sent for Keypad 4, instead the event for Left Arrow is sent. Having Num Lock on is just going to always lead to problem if you're using Shift + number pad combinations.

    Another Unity keyboard artifact:
    Hold Left Shift, then press and release Right Shift. Right Shift will stay on until Left Shift is released.
     
    Last edited: Aug 14, 2018
    ArachnidAnimal likes this.
  8. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,832
    Thanks for looking into it. Personally, I am in no rush at all to receive any Rewired asset updates regarding this (If you do decide it is worth updating the asset to address this issue).
    I guess the usage of numpad keys in games is not really that common.
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Using the number pad isn't that unusual. Doing more poking around, it appears the problem lies in the use of Windows VKeys. If you were to simply use the raw make codes from the keys, the number pad would simply be 9 keys regardless of the numlock setting which you could interpret however you want. No key up events would be lost. This would probably be the most appropriate method for most game input (other than text input). Rewired's Windows native keyboard input system was written to replicate what Unity's system does for the most part, mapping directly to the same KeyCodes Unity returns for keys. Apart from a few implementation differences that you discovered with these VKeys, it's basically the same. While I could change it to use the raw make codes, it would break existing games that rely on the user being able to map things to the arrow keys and have those work on the number pad by just turning off num lock. It would also complicate things requiring some kind of way to differentiate keyboard input for text input and keyboard input for gameplay input since you'd really want the keys to work in the normal way for text input.

    This is something I'm going to have to think about for a while.
     
  10. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Hi @guavaman, just checked out the new mouse cursor feature, just to get familiar with it. Started by looking at the examples, then created my own cursor and scene to test my ability to use it. :) Works great!

    This is what I did:

    1. Created a mouse cursor image, imported it as a sprite.
    2. Created a empty GameObject under a Unity UI canvas, added UIPointer.cs to it.
    3. Created a Unity UI "Image" under that and assigned the cursor sprite.
    4. Adjusted the pivot point of the Image GameObject's Rect Transform so that the pointy bit is the active part of the cursor.
    5. Set up Rewired Input Manager with actions and mappings for cursor movement and a left click.
    6. Added a GameObject with a Player Mouse and configured it.

    Would it make sense to have UIPointer available outside of the Rewired.Demos namespace? Seems like it's pretty generic (and rather useful in that context).

    On a side note, does it seem strange that once you click a button (or whatever) in Unity UI, it keeps it highlighted even after the cursor leaves the control? I expected the more traditional "hover" behavior. Haven't used Unity UI much, so that surprised me. It's nothing to do with Rewired I don't think, but at first I thought I was doing something wrong. :)
     
    guavaman likes this.
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Great! Glad to hear someone is trying it out. I tend to not get much feedback about features or even know what people are using, so thanks for that. Your process sounds exactly right.

    As for UIPointer, I purposely did not include that as part of Rewired because I felt it was somewhat outside the scope of what I thought the input system should provide. Also, it only works for Unity UI. But you might be right... Having thought about it, I was sure people would expect the pointer to have all kinds of fancy features it doesn't have like animation, context-sensitive graphics/behavior, effects, trails, ability to map onto all Canvas modes (world-space UI pointer?), etc. From experience, I know that every time I have added a new "make things easier" feature, it has tended to end up a can of worms as users expect more and more push-button, built-in functionality from that feature. So adding a new feature that is sort of bare-bones always ends up either snowballing into a do-everything system or results in bad reviews and/or complaints because it didn't do something out of the box that someone wanted it to. My purpose was just to show how you could do it simply and have something to show in the demo scenes. Leaving it just as sample code, the developer is free to copy and paste it and expand it however they like.

    It's just the default behavior of the Button component. The purpose is keyboard/joystick navigation. Once you click something, you are selecting it. After something is selected, you can then navigate around the UI using keys/joystick. You can disable it by changing Navigation to None in the Button inspector.
     
    Steve-Tack likes this.
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Rewired 1.1.19.1 is available on the Unity Asset Store.

    See Updating Rewired before updating.

    1.1.19.1:

    Bug Fixes:
    - Editor DLL: Updated Rotorz Reorderable List due to breaking changes made in Unity 2018.2 API.
    - Windows Standalone, Raw Input + Native Keyboard Handling: Keyboard no longer returns key values the frame after being enabled if any keys were pressed when the Keyboard was disabled.
    - Windows Standalone, Raw Input + Native Mouse Handling: Mouse no longer returns button values the frame after being enabled if any buttons were pressed when the Mouse was disabled.
     
  13. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    I have been playing with a little bit and just fired up the two demos mostly. But @Steve-Tack has done so more digging. It looks like it will be very useful. It is nice to be able to use a controller and not just a mouse. More exciting digging for sure ... :)
     
  14. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    @guavaman @Steve-Tack

    I thought I have seen everything when it comes to interesting controller combinations. But this one is really good. A farm controller and Rail Driver controller. Wow that looks like something worthy of being tested together.Rewired supports them both of course. Not sure what is being used software wise but it looks exciting to me.

    Front: Logitech heavy equipment side panel. Rear: RailDriver train control stand.

    https://twitter.com/erkpod/status/1007112936744030209
     
    guavaman likes this.
  15. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85
    Hi @guavaman ,
    I've been trying to setup a 3DConnexion space mouse,
    when I used the 6DOF template, the two buttons of the space mouse don't work.
    I mean rewired recognizes the space mouse perfectly, but buttons wouldn't work with the template.
    I created a map for the space mouse in particular and the buttons work fine.. just that they don't respond when used with the template..

    Unity version 2018.1.5f1
    Rewired version 1.1.19.1
     
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    What is the exact model of the space mouse being used?
    What platform?

    Everything is correctly set up on all space mouse definitions and the template file. I see no possibility of errors.
    1. Run the DevTools/JoystickElementIdentifier scene.
    2. Select the space mouse with +/-.
    3. Press the buttons on the controller and tell me what it shows.
    4. Post a screen shot of the screen displayed for the mouse.
    Use Debug Information to view the Controller Maps loaded for the Player in real-time.

    What does Debug Information show the device recognized as? Controllers -> Joysticks -> the joystick -> Name it shows.
     
    Last edited: Aug 16, 2018
  17. imaginationrabbit

    imaginationrabbit

    Joined:
    Sep 23, 2013
    Posts:
    349
    Hello- I've been getting random hangs in the Unity editor when pressing play in scenes using Rewired- I'm using Rewired 1.1.18.0.U2017 with Unity 2017.3.1f1

    This is the last part of the Editor log before it locks up the editor and I have to force quit-

    Code (CSharp):
    1.  
    I've run DirectX diagnostics and there are no problems with it- I don't know if its related to Rewired- just trying to track down the issue- is this something you've seen before? Thank you.
     
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Those fallback handler messages are completely normal. All it tells me is that you are not using Windows 10 because you don't have XInput1.4.

    There is no known crash scenario with any of the native Windows libraries. Update to the newest Rewired and re-test.
    1. What is your Primary Input source set to? Rewired Input Manager -> Settings -> Windows
    2. What options do you have enabled? Rewired Input Manager -> Settings -> Windows
    3. What devices are connected?
     
    imaginationrabbit likes this.
  19. imaginationrabbit

    imaginationrabbit

    Joined:
    Sep 23, 2013
    Posts:
    349
    I will update Rewired and re-test- thank you.

    Here is the Windows settings


    The only connected device is a single Xbox360 controller BUT the controller has been buggy- randomly connecting/disconnecting recently- it works when needed but the console shows it random Connecting/Disconnecting
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    That is definitely suspect. If the failure happened while initializing XInput, that would be the only reasonable conclusion. That may or may not be indicated by the point at which the log ended because Rewired doesn't log anything in general with regards to initialization unless there's a problem, so it may not be where the failure is happening.

    Disable Use XInput and test. If it solves it, then you know it's something to do with that. If not, re-enable and disable Native Moues Handlong, Native Keyboard Handling, Enhanced Device Support one at a time and test. If none of that works, change Primary Input Source to Direct Input and test. Then Unity input. This is the usual procedure to figure out which component is running into the problem.
     
    imaginationrabbit likes this.
  21. imaginationrabbit

    imaginationrabbit

    Joined:
    Sep 23, 2013
    Posts:
    349
    Thank you so much for the detailed answers- I've disabled Xinput in the settings and it hasn't locked up since- I will keep testing using your instructions- thank you.
     
  22. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Disabling XInput is not recommended as you lose a ton of features.

    When this happens, is it crashing consistently? Does it happen on the first Play run or is it always on subsequent Play runs? Does it happen when the controller is not connected?
     
    Last edited: Aug 17, 2018
  23. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85
    The exact model is SpaceMouse Wireless.

    Here are the screenshots from the DevTools/JoystickElement Identifier scene. I've pressed both the buttons.
    Screenshot_Rewired_SpaceMouseWireless.png Screenshot_Rewired_SpaceMouse2.png
    Everything in my scene seems to be setup correctly, even the SpaceMouse axes give the correct output with the template, just the buttons that don't work.
     
    Last edited: Aug 17, 2018
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    There's nothing wrong with the template file or the controller definition. Everything is correct as far as I can tell. They should work.

    Use the Debug Information tool to look at the Controller Maps loaded in your Player:

    fewafew.png

    If you have created a Space Mouse-specific Controller Map in the same category/layout, delete it because it will override the Template map.

    If you are using Control Mapper or UserDataStore_PlayerPrefs, delete PlayerPrefs because you'd be loading old XML data.

    View the values of the Actions in the Player directly:

    fewfe.png

    View the button values in the Controller Template directly:

    2342.png
     
  25. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85
    I have deleted the space mouse specific map.. everything else is vanilla,
    I've only created player0 and assigned it a joystick map

    Template setup:
    Screenshot (361).png

    Player actions on the left , controller inputs on the right
    Screenshot (364).png

    Controller inputs on the left, template values on the right
    Screenshot (368).png

    You can notice that the button press is detected in the controller input, but isn't translating to the template or the player actions, but the axes values are showing up.
     

    Attached Files:

    Last edited: Aug 17, 2018
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    The picture showing the Template buttons saying Exists = False proves something is wrong with the template.

    While all the mappings are all showing correctly in the template, the file guid was wrong, therefore the map was using the element identifier ids from the Space Pilot Pro. Even though it looks correct, the axes all lined up, but the buttons did not.

    Download the template file:
    https://www.dropbox.com/s/jql1dx7b65gjhrf/SixDoFController.asset?dl=0

    Replace it in Rewired/Internal/Data/Controllers/HardwareMaps/Templates
     
    vivalavida likes this.
  27. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85
    Success, it works!

    Thanks.
     
    guavaman likes this.
  28. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85
    @guavaman as a feature request, would it be possible to support midi controllers?

    I'm not sure if this falls in the scope of Rewired and/or how much work is involved, just thought I'd ask.
    Thanks.
     
  29. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    It would be a huge task, without question. Midi is so different from joystick/keyboard input that I'm certain it would require completely new controller constructs, new mapping constructs, new editors, new ways of querying for input, and much more. Then you have to consider the number of platforms that would have to work on. You're only the 2nd person to ever ask about this, so it would be a gigantic task and likely nobody would use it. I don't have any plans to add midi support to Rewired.
     
    vivalavida likes this.
  30. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    If we could just find a way to clone you. :) I think midi only makes sense on Windows and Mac. All other platforms it is basically almost impossible because none of the midi instruments/controllers support them officially for the most part. We can always use custom controllers in Rewired to feed any of these other input options into the system currently.

    Thanks for all your hard work on Rewired.
     
    vivalavida and guavaman like this.
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    I would definitely go for that. Then one of us could actually take a break once in a while. With my luck, it would be the other guy. :rolleyes:
     
    flashframe and vivalavida like this.
  32. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Have you looked at any of the midi unity assets in the store? It seems like you could just use one of them to feed into a custom controller with Rewired. This is one what looks really useful from the midi point of view. It looks interesting since most implementations (unity asset) do not support rtMiidi. More info can be found here.

    https://assetstore.unity.com/packages/tools/audio/giavapps-midi-103095
     
  33. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Hi @guavaman

    I'm having a problem and I do not know how to fix it ...

    I'm using touch1isTouching = joystick.GetExtension <PS4GamepadExtension> ().GetTouchPosition (0, out touch1Pos); For PS4 builds

    and I'm using touch1isTouching = joystick.GetExtension <DualShock4Extension> ().GetTouchPosition (0, out touch1Pos); For PC builds

    I have a code that goes perfect on PC but the same code for PS4 is not going well and has wrong behavior.

    The only difference between the two codes is that of GetExtension <PS4GamepadExtension> and GetExtension <DualShock4Extension> And doing tests I see that in the PS4 build, touch1isTouching is always true, even if I do not touch the touchPad with my fingers, and this is what I think which causes the problem in the operation of my script.

    Can you tell me how I can solve this? Does not the GetTouchPosition () function behave in the same way if it runs under PS4?

    regards
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    They are not the same function. Rewired on PS4 uses UnityEngine.PS4.PS4Input to get the value of all the special functions. These values are determined by Unity and the PS4 SDK. Everything on the PC is completely written by me from scratch reading raw data from the controller. My re-creation of their API may not be 100% the same as how the PS4 represents it.

    There is no "touch1IsTouching" property on either the PS4 or PC versions of the Controller Extension. There are two functions to get the "is touching" state:
    IsTouching(int index)
    IsTouchingByTouchId(int touchId)

    Which one are you using and what does it return on PS4 when nothing is being touched?

    Ultimately at the lowest level all this function does is check if the returned touchId from PS4Input.GetLastTouchData is >= 0. If this is returning true every frame, then the id being returned by Unity is >= 0. What do GetTouchId(0) and GetTouchId(1) return when you aren't pressing anything?
     
    Last edited: Aug 19, 2018
  35. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    I see this asset was released Nov 9, 2017 and has only 2 reviews. Judging by this, I'd say the number of Unity developers interested in Midi support is indeed extremely small.

    It looks pretty full-featured. And just by the description, I can already tell that it would require a completely separate Midi API to really support all the features of Midi natively in Rewired. Using a Custom Controller would allow you to pipe keys in as Action axis/button values to treat a Midi device as a normal game controller, but it would not give you access to all the power of Midi.
     
  36. nlebedenco

    nlebedenco

    Joined:
    May 12, 2014
    Posts:
    11
    Hi @guavaman

    after importing Rewired 1.1.19.1 in a Unity 2018.2 project the console showed a bunch of warnings about type name clashes like the one below:

    Assets/ReorderableList/Editor/Element Adder Menu/GenericElementAdderMenu.cs(9,50): warning CS0436: The type `Rotorz.ReorderableList.IElementAdderMenu' conflicts with the imported type of same name'. Ignoring the imported type definition

    I inspected the Rewired_Editor.dll and it's exporting some but not all types from the Rotorz.ReorderableList namespace which is producing the clash with an existing ReorderableList installation. I believe the Rewired_Editor should not be leaking type definitions like this. Even if they are part of the API, they should be encapsulated in the Rewired.Editor namespace. Perhaps this a harmless warning but since we don't have access to the source code you used for that assembly we can't really know for example if your Rotorz.ReorderableList.ElementAdderMenuBuilder was customized and is now being unintentionally overridden by a local ReorderableList instalation.
     
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    They were all supposed to be encapsulated. They always have been. This new update to Rotorz Reorderable List in 1.1.19.1 due to Unity's breaking change added several new files that I missed.
     
    Last edited: Aug 19, 2018
  38. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    @guavaman the touch1isTouching parameter is only a bool variable that I declare.

    In PC it works perfect but in PS4 GetTouchPosition () always returns true ... even if it does not touch the gamepad.

    But the values that it returns from the TouchPad position in PS4 with GetTouchPosition() when the control is not touched with the fingers, is the last value that you touched ... that is, it does not reset to (0,0) as it happens in PC with the same function GetTouchPosition ()

    On the other hand in PS4 the function isTouching (0) and isTouching (1) also always returns true even if the touchpad is not touched
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Contact me here to get 1.1.19.3 early or wait for it to show up on the Asset Store probably next week.
     
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    I understand that. Please contact me here so I can try to change this behavior send you private builds.

    You could use the touchCount property to determine how many if any touches are present.
     
  41. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    @guavaman
    I do not know what that property is. I only find in your Api "maxTouches"
    Can you explain me a little more?
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    It was added to DualShock4Extension in 1.1.19.0 for consistency with PS4GamepadExtension (already exists on that class) so the new common IDualShock4Extension interface can be used for both. If you don't have it, you're using an old version of Rewired. But it was always there on the PS4GamepadExtension.

    It returns the number of touches currently present which is correctly returned by the PS4 SDK. So instead of IsTouching, you can determine how many touches are occurring with touchCount. Use the touchCount to determine what indices have touches. A touchCount of 2 means index 0 and 1 have touches. A touchCount of 1 means only index 0 has a touch. A touchCount of 0 means there are no touches.

    I have made an update that does this under the hood and should make IsTouching work on the PS4. Contact me here to get it.
     
  43. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Got it. I guess in theory the advantage of having something like that be a "real" Rewired class is that when there are fixes or enhancements, you get them automatically. The downside is that now you've got a new dependency. It's always something. :D
     
  44. nlebedenco

    nlebedenco

    Joined:
    May 12, 2014
    Posts:
    11
    It's going to take me a few days anyway to complete the integration on my end so if you say this should be addressed in the next version to come out in a matter of weeks I can wait for the update. It's good to know you got it on your radar already, though! Thanks for the the quick reply, btw! -- cheers.
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    I uploaded it to the asset store already, but they take some time to approve an update. It will probably be out next week, but that depends on their workload.
     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    No truer words.
     
  47. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    @guavaman
    I have contacted you through the channel that you indicated to me so that you send me the last patch of rewired and test if it goes well in PS4 builds.

    Confirm that my request arrived

    regards
     
  48. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Not sure what the other person was expecting for midi exactly since it was not spelled out or what platform (Windows or MAC)

    I would expect that most people have not used MIDI except to maybe playback midi files which is not the same. But these days you can get midi controllers for a pretty inexpensive price to close to $100. For example the Nectar Impact LX25+ MIDI controller or Akai MPK Mini mkII. On Windows and MAC it just plug in the usb cable it is automatically detected as a USB device (as defined in the USB spec) and you are set. If you have older midi devices (that use 5 pin style cables) then you need a USB midi adapter. I have a really old (1980s era) Casio CZ-101 midi keyboard and that works fine also (with a proper USB midi adapter since it uses 5 pin din)

    Probably more people were using an earlier asset from a different unity asset store vendor but at least from what I have seen in the forums that asset has some issues.. Since this one is much newer and supports rtMidi (no other mid assets have implemented that). It is also limited to Windows and MAC platforms only as expected.

    There are also free midi tools like Midi Jack for Unity. Note it also limited to Windows and MAC which makes perfect sense. More info can be found here (including complete source code and be used in commercial products based on the license).
    https://github.com/keijiro/MidiJack

    MidiJack provides note on/off (keys), pitch bend, knobs, drumpads, on the LX25+ so that works fine. I only tested on Windows and not MAC. Other than notes and some system exclusive messages it works already.

    You get the note on/note off [values 1-127] and velocity without having to do too much work (using the provided examples in midijack). You can also get the knobs, and drumpads (typically mapped as notes plus a velocity), and pitchbend without any work. And then feeding those into Rewired custom controller works just fine.
     
    vivalavida likes this.
  49. s8cusyqr

    s8cusyqr

    Joined:
    Jul 9, 2018
    Posts:
    7
    I want to disable maps for a player on start of game in Awake, but at start it returns nullreferenceexception, because reinput isnt initialized yet. So, I create loop:
    Code (CSharp):
    1.  private bool mapsdisabled = false;
    2.  
    3.         public void Awake()
    4.         {
    5.             while (!mapsdisabled)
    6.             {
    7.                 if (ReInput.isReady)
    8.                 {
    9.                     ReInput.players.GetPlayer(0).controllers.maps.SetAllMapsEnabled(false);
    10.                     mapsdisabled = true;
    11.  
    12.                 }
    13.            
    14.             }
    15.         }
    But then game is stuck in awake.
    I tried to create a new thread:

    Code (CSharp):
    1.    private bool mapsdisabled = false;
    2.  
    3.         public void disable()
    4.         {
    5.             while (!mapsdisabled)
    6.             {
    7.                 if (ReInput.isReady)
    8.                 {
    9.                     ReInput.players.GetPlayer(0).controllers.maps.SetAllMapsEnabled(false);
    10.                     mapsdisabled = true;
    11.  
    12.                 }
    13.            
    14.             }
    15.         }
    16.     private Thread _t1;
    17.     void Awake() {
    18.         _t1 = new Thread(disable);
    19.         _t1.Start();
    20.     }
    But it is stuck too.
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,631
    Those approaches would never work.

    Your first approach is guaranteed to infinite loop. Unity cannot continue execution when you put it into a while loop. All scripts in Unity initialize on the same thread. Awake in one script will never run while Awake in another script is still executing. They all take turns. Your while loop is blocking all others from ever executing.

    Your second approach would never work because neither Rewired nor Unity are threadsafe. They can only be accessed on the main thread.

    If you want to delay execution of tasks in Unity, learn about Coroutines:
    https://docs.unity3d.com/Manual/Coroutines.html

    However, your specific problem does not require coroutines at all.

    #1. Rewired's Script Execution Order of -32,000 guarantees that it will run Awake before any other scripts run Awake. Therefore, if your Rewired Input Manager is in the scene and enabled at the time you start the game, Rewired will always be Awake before any other script. The only scenario where you could ever have another script execute before Rewired is if you are instantiating the Rewired Input Manager from another script. If your script that instantiates the input manager's Script Execution Order is not set to execute before your other scripts, Rewired will not be initialized before others. A tool was provided for you to be able to instantiate the input manager without running into this problem -- Rewired Initializer: http://guavaman.com/projects/rewired/docs/InputManager.html. It also has a very low Script Execution Order so it's guaranteed to instantiate the input manager before your other scripts run.

    Apart from all this, as with all scripts in Unity, you can always put code in the Start() method which is guaranteed to run after the Awake() method in all scripts. There is no need to do this.
     
    Last edited: Aug 20, 2018