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:
    4,010
    Hi,

    Please see the FAQ for the answer to this question.

    Obviously, make sure it is a private repository.
     
    Last edited: Nov 6, 2017
  2. IGY-United

    IGY-United

    Joined:
    Feb 24, 2013
    Posts:
    4
    Hello, i am having an issue with some controllers.
    The problem is the one you described in FAQ, with Rewired's automatic controller recognition system not being able to work with generic controllers.

    And indeed, these are the controllers that do not work:

    Controller (Game Controller for Windows)
    - WindowsFallbackController(GameControllerforWindows)
    - 00000000-0000-0000-0000-000000000000

    Generic USB Joystick
    - WindowsFallbackGenericUSBJoystick
    - 00000000-0000-0000-0000-000000000000

    But the thing is, the controllers work in other games normally (without asking players to map it out first).
    So i am wondering how do other developers handle this problem?
    I am just trying to make it more convenient for players.

    Thanks!
     
  3. tspk91

    tspk91

    Joined:
    Nov 19, 2014
    Posts:
    117
    Hello, how can I detect which Template is automatically selected for a joystick? We need to know when a controller is of HOTAS type (any of the models that fall back to the hotas template), and we dont want to check guids one by one. I looked for a streamlined way to get this in the api but with no success.
     
  4. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,463
    What are the name of these controllers by the way? Sounds the like the "infamous" dragon rise series of generic controllers.

    You need to define a mapping for an unknown controller. See the best practices page in the docs for details on that and other good ideas to think about.

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

    Also you should consider adding control mapper so in case someone has a real strange controller so that the end user can remap it as needed.

    http://guavaman.com/projects/rewired/docs/ControlMapper.html
     
    Last edited: Oct 24, 2017
    IGY-United likes this.
  5. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,463
    Are you displaying or doing something specific to HOTAS compared to a gamepad? Just trying to understand what your use case is. What version of Rewired and what platform are you building for?

    Never had a need to detect something specific for each template type but I was just more concerned that a user can start playing with the most popular controllers and HOTAS setups and even a racing wheel. I have an example of what I did in the RFPS posted here.

    https://forum.unity.com/threads/realistic-fps-prefab-released.176985/page-69#post-2921727
     
  6. IGY-United

    IGY-United

    Joined:
    Feb 24, 2013
    Posts:
    4
    Thanks man, this was helpful. I already made my own custom control mapper.
    Somehow all this time i though that we should never map unknown controllers because its impossible to get it right.
    But you are right, some kind of mapping is better than none.

    I will investigate more what are common layouts for these generic controllers and create mapping for them.
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    This FAQ question explains these controllers and why they cannot be automatically mapped:
    http://guavaman.com/projects/rewired/docs/FAQ.html#addding-controller-definitions

    Either the game you are testing with recognizes these controllers directly and would therefore map another of the same type incorrectly or they just have a default generic mapping (like Rewired's Unknown Controller) that just happens to work well enough. If you look at the SDL2 controller definitions for example, they have many of these problem controllers recognized. The problem is, if the user doesn't use the exact same controller they made the definition for, the mappings are all wrong.

    There is no common layout for generic controllers. I can say this because I own a ton of them and they're all over the place. The recommendations in the documentation for the Unknown Controller in the docs are as close as you can get. For buttons, they will vary from controller to controller more than the axes, but sometimes the order is A, B, X, Y, L1, R1, L2, R2, Back, Start, LSB, RSB.
     
  8. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    This is the reason:
    http://guavaman.com/projects/rewired/docs/ControllerMaps.html#controller-templates

    Controller Templates are only intended for developer use. Templates simply provide a shortcut to allow the developer to define mappings for many controllers at once without having to create individual mappings for every supported device manually. Templates are not available to the end user for remapping purposes. When Controller Maps are loaded, they are converted from the Controller Template map to a native Controller Map for that specific device. The Controller Template no longer has any relationship to the runtime Controller Map that was loaded from it. The end-user cannot modify the developer-defined template mappings. If you were to display a list of element names on the controller for the user to map, it would not be a list of template element names, but rather it would be a list of named elements from that specific device.

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

    Controller templates are not for the purpose of denoting a controller type and are not designed to be used at runtime or for any other purpose than the above. More than one template may apply to a Controller Map as well.

    Using Controller Templates at runtime is not a recommended use of the system, however it is possible. This method was added to get generic template identifiers for controller elements:

    http://guavaman.com/projects/rewire...GetFirstJoystickTemplateElementIdentifier.htm

    To get a template type, you have to use undocumented methods intended for internal use only as follows:

    Code (csharp):
    1. void ListJoystickTemplates(int playerId) {
    2.     Rewired.Player player = ReInput.players.GetPlayer(playerId);
    3.     foreach(var joystick in player.controllers.Joysticks) {
    4.         foreach(var guid in GetControllerTemplates(joystick)) {
    5.             Debug.Log(joystick.name + " uses " + GetTemplateType(guid));
    6.         }
    7.     }
    8. }
    9.  
    10. IEnumerable<Guid> GetControllerTemplates(Joystick joystick) {
    11.     var rim = GameObject.FindObjectOfType<InputManager_Base>();
    12.     var definition = rim.dataFiles.GetHardwareJoystickMap(joystick.hardwareTypeGuid);
    13.     if(definition == null) return new List<Guid>();
    14.     return definition.TemplateGuids;
    15. }
    16.  
    17. TemplateType GetTemplateType(Guid guid) {
    18.     if(guid == templateGuid_dualAnalogGamepad) return TemplateType.DualAnalogGamepad;
    19.     if(guid == templateGuid_FlightPedals) return TemplateType.FlightPedals;
    20.     if(guid == templateGuid_FlightYoke) return TemplateType.FlightYoke;
    21.     if(guid == templateGuid_HOTAS) return TemplateType.HOTAS;
    22.     if(guid == templateGuid_RacingWheel) return TemplateType.RacingWheel;
    23.     return TemplateType.Unknown;
    24. }
    25.  
    26. public enum TemplateType {
    27.     None = 0,
    28.     DualAnalogGamepad = 1,
    29.     FlightPedals = 2,
    30.     FlightYoke = 3,
    31.     HOTAS = 4,
    32.     RacingWheel = 5,
    33.     Unknown = int.MaxValue
    34. }
    35.  
     
  9. Nifflas

    Nifflas

    Joined:
    Jun 13, 2013
    Posts:
    113
    I have got my reference to an instance of a Joystick class! Now, I'd like to know whether it's a Dual Analog Gamepad or not. Is there an easy way to check this?
     
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
  11. tspk91

    tspk91

    Joined:
    Nov 19, 2014
    Posts:
    117
    Thanks for the detailed snippet. The only intended use for this in our game is to treat dual gamepad axes diferently from hotas/flight stick ones. Where the throttle of a hotas is used directly to map to a velocity, we process the "speed" axis in dual gamepads so that it moves a velocity value, so it increases/decreases proportionally to the axis value. If not from a template, how could we do it? We want to avoid going through a manually defined list of possible hotas controllers.
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    I would recommend using different Actions for the two types. If you don't want to do that, there's no other way if you want to treat values returned by some particular joystick axis differently on different controllers. There is no metadata provided by the device or Rewired about what exactly an axis is, so no this is a "Throttle", this is a "Stick", "Rudder", "Trigger", "Dial", "Rocker", "Spinner", "Pedal", "Wheel", etc. You either have to use the controller template through the undocumented code shown above or make a lookup table using the joystick.hardwareTypeGuid like is done for controller element glyphs.
     
  13. tspk91

    tspk91

    Joined:
    Nov 19, 2014
    Posts:
    117
    Well that pretty much solves it (using a different action). I was looking at the problem in the wrong angle way too hard!
     
    guavaman likes this.
  14. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    141
    Hi!

    Since a couple of weeks (give or take) we're experiencing an issue where a single controller connects twice.
    The second 'non-existing' controller is automatically disconnected.

    So a typical scenario would be.
    - Game is running - no controller connected
    - Xbox 360 wireless controller connects (as XInput Gamepad 1) -> gets properly assigned by the game
    - 'Another' Xbox 360 wireless controller connects almost instantly as well (as XInput Gamepad 2) -> is ignored (since there are not enough players)
    - The second controller almost instanlty disconnects -> a disconnect dialog is shown by the game.

    We notice that the OnControllerConnected is called twice. There is only one script (instance) with this callback.

    We are only experiencing this on Windows 10 - Maybe since the last update (4 October) but we can't say for sure.
    The issue does not occur on a Win 7 machine.

    We tested with the latest Rewired build, but the issue still occurs.

    We experience the same issue with a Xbox One controller.

    Anybody have the same issue? Maybe a solution or some tips?

    Thanks,

    Pieter / Xform
     
  15. biegunl

    biegunl

    Joined:
    Jun 24, 2016
    Posts:
    9
    I have the same issue. OnControllerConnected is called twice when I plug in my Xbox One Controller in Editor. I discovered it a moment ago.

    EDIT: Everything is working fine and event is calling once when i plug in different controller like Logitech Whell 920.
     
    Last edited: Oct 25, 2017
  16. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    Because you say it's showing up as XInput Gamepad 2, this means it's directly an XInput issue. Rewired will not detect or see anything from XInput unless XInput's function for checking whether a device is connected returns True. That means XInput has a new bug and Rewired is not able to prevent it because it can get no information about XInput devices except through those XInput functions. The attached script will show you directly from the XInput DLL what it's reporting. Attach it to a game object and press play.

    If it's firing OnControllerConnect twice, two devices must be appearing. It would also fire OnControllerDisconnect when the fake device disappears. Is this the case? And is Use XInput enabled in Rewired Input Manager -> Settings -> Windows?

    I cannot reproduce either issue in Windows 10 1703, 15063.674 using a wired Xbox 360 Controller or a wired/wireless Xbox One S controller.

    If you have any software installed that creates emulated XInput devices such as VJoy, DS4Win, etc. try removing it. If you are running it with Steam, try not initializing Steam.
     

    Attached Files:

    Last edited: Oct 25, 2017
  17. biegunl

    biegunl

    Joined:
    Jun 24, 2016
    Posts:
    9
    Yes this is the case, i attached your xinput script and it showing two devices for a second (showing up and instantly dissapearing). I have XInput enabled.

    It looks like it is happening because of Steam :( Do you have any solutions for this? The problem is that my game was developed to work with steam.
     
    Last edited: Oct 25, 2017
  18. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    There's no solution or even workaround possible on Rewired's end. Rewired cannot get any information about XInput devices except through XInput. There's no way to determine if one XInput device is real and one is not. Steam does all kinds of XInput hacking (drivers that make emulated devices) to make their Steam Controller and Steam Streaming work and this is likely due to that. Please report the bug to Steam.

    If you are using the beta client, try reverting to the non-beta or vice versa.
     
  19. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    141
    Thanks for the feedback so far!

    We use Steam as well. I don't understand why this issue is then only in win10 and not in win7. Can you elaborate?

    I'll check the script first ting tomorrow morning.

    Btw the issue occurs both ingame and in editor - so how could Steam cause this in editor when it is not enabled or active ?

    Thanks again - will double check everything tomorrow!

    -Pieter
     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    Windows 7 and Windows 10 use different drivers for Xbox One controllers and different versions of XInput. It could also have something to do with other software you have installed messing with XInput. There are a ton of variables that can change from system to system.

    There's no guarantee your issue is the same as @biegunl's issue. You would need to do testing to find out if it is. You can use the same file I posted above to see the raw information from XInput. You can also log the ReInput.ControllerConnectEvent results to get the name of the Joystick being created by Rewired. If it's XInput Gamepad #, then this is probably the same issue.

    Code (csharp):
    1. void OnControllerConnected(ControllerStatusChangedEventArgs args) {
    2.     Debug.Log("A controller was connected! Name = " + args.name + " Id = " + args.controllerId + " Type = " + args.controllerType);
    3. }
    You are not initializing Steam in the editor?

    I don't really know how Steam's XInput emulation system works internally so I can't say. If this is a Steam issue, it may affect non-Steam applications depending on what their driver is doing. If this isn't a Steam issue, then it's probably either another Xbox One driver problem or some other application creating an emulated XInput device.

    What I can say for sure is, if XInput is reporting the device as connected, there's nothing Rewired can do to hide it.
     
  21. Crusare

    Crusare

    Joined:
    Feb 14, 2014
    Posts:
    21
    Hi there,

    Rewired works fine for me on PC, but on XBox One, it doesn't even detect the wireless controller (the displayed debug info doesn't register a controller). Funny thing is, it works fine when using the default, built-in Unity functions (so Unity definitely detects the controller). Any ideas about solving this?
     
  22. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,463
    What version of Unity?
    What version of Rewired are you using?
    What version of windows are you using?
    What is the name of the wireless controller that you are using?

    Are you building for Windows 10 (universal app) for XBOX ONE or using building using a XBOX ONE dev kit?
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    .
    Xbox One:
    http://guavaman.com/projects/rewired/docs/SpecialPlatformSupport.html#xbox-one

    I have no other reports of input on Xbox One not working. Rewired uses UnityEngine.XboxOneInput.GetControllerId to poll all connected controllers on Awake and UnityEngine.XboxOneInput.OnGamepadStateChange to get controller connect and disconnect events after that. If Rewired is reporting no controllers, neither of these would be reporting connected controllers. The only circumstance where Rewired would ignore connections is if the controller returns a blank string name from XboxOneInput.GetControllerType.

    Is there anything in the log?

    In the Debug Info, I'm assuming you're using the prefab from Rewired/DevTools because the editor cannot run on the Xbox One. Did you open Controllers -> Joysticks?

    Xbox One UWP:
    http://guavaman.com/projects/rewired/docs/SpecialPlatformSupport.html#windows-uwp

    I tested this just days ago and everything works. You must set it up as shown in the documentation at the link above.
     
    Last edited: Oct 27, 2017
  24. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    @Crusare By the way, is this .NET or IL2CPP scripting backend?
     
  25. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,623
    So first off I really like Rewired. One thing I think you guys could add to the package that would be a high perceived value is a generic abstraction for managing which inputs should be available. Pretty much every game needs that layer.

    Not only for things like actions comprised of multiple actions (like CTRL SOMEKEY combo), but stuff like gathering all input fields to check for if they are focused, and not allowing input in that case. Or toggle logic where you can say this input is exclusive, while it's toggled on other inputs are blocked. Or if input A is toggled on and B fires, A (and possibly any other active toggles) get deactivated.

    I think the list of the most common scenarios here is fairly short. And I know in my own implementations I've been able to keep that logic completely self contained.

    Another note, the generate constants is nice, but enums would be better. VS autocomplete is one reason, and it's also easier when you want to expose some type of configuration in your own editors.
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    Thanks!

    This can already be done in various ways using the Controller Map system by layering your input into different Controller Maps and enabling/disabling the layers based on what is currently active. Individual mappings can also be enabled/disabled. I have quite spent time coming up with ideas on how to make something like you're describing (but very generic and able to cover many user cases) easier, but it would require either a completely new layer on top of the current system or a major breaking overhaul to the mapping system.

    However, some of the potential use cases may be overlapping into the area of game permissions / state management. It is my belief that the input system should be only concerned with getting user input and providing that to the developer. Decisions about whether or not to allow that input to result in some action would be the task of the consumer of that user input.

    I think this FAQ answer explains where I'm coming from on this topic:

    How do you consume/use an input?
    There is no "consume" or "use" concept in Rewired. You cannot change or override the final Action input values because they are set by the hardware events and then calculated based on combined values of all input sources that contribute to that Action.

    This question is almost always asked due to the desire to use the input system as part of in-game player state/permission management. For example, you should not think of Rewired's Player.GetButtonDown as a flag denoting "game player is now firing". It should be thought of as a signal of the user's intent entirely separate from the game simulation. GetButtonDown("Fire") is equal to "the user wants to fire". Whether or not the game player is allowed to fire at that moment is a game player state management issue and needs to be handled in your game code.

    "User wants to fire" -> If "game player is allowed to fire" -> then "fire".

    Using Rewired or any input system as an integral part of game state or permission management is not a correct usage. This way there is no need for something like consuming input and injecting your game state permission management into the input system.

    ------

    By the way, Rewired has keyboard modifier key support built in.

    Except there's a problem -- the Rewired API cannot be written to expect to receive values from various not-yet-existent enums which you will be generating. Using an enum would require the user to cast the value to an int every time they want to interact with the Rewired API. If the API were written to use the generic System.Enum instead, every call would generate memory allocations leading to garbage collection issues.

    Exposing them in an editor is as simple as adding a single attribute to your variable:
    http://guavaman.com/projects/rewired/docs/HowTos.html#actionid-property-drawer
     
    Last edited: Oct 29, 2017
  27. utkarshdwivedi3997

    utkarshdwivedi3997

    Joined:
    Aug 11, 2017
    Posts:
    18
    Hey, so I've the updated version of Rewired, and I'm still getting this issue. Every time I hit the play button, Unity becomes completely unresponsive and I have to end the task using task manager. I'm using Unity 5.6.0f3 and Direct Input. I've tried reinstalling Unity, reimporting Rewired, and I've also tried porting a copy of my project to Unity 2017.1. Upon porting it to 2017.1, the Unity Editor playmode worked once, and now it doesn't work on 2017.1 as well. I'm fairly certain that this issue is being caused by Rewired, because the moment I deactivate the Rewired Input Manager game object, play mode starts working. Any help would be appreciated!

    Edit: Oh, also, I'm using Rewired version 1.1.7.5. We're using Unity Collab to work on this project, and everyone else seems to be able to run play mode just fine.
    Thanks!
     
    Last edited: Oct 29, 2017
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    It cannot be the same bug that was fixed in 1.1.4.2. The current version on the Unity Asset Store is 1.1.7.8 which has several bug fixes since 1.1.7.5.

    Do the following:
    1. Disable XInput - Rewired Input Manager -> Settings -> Use XInput. Press Play.
    2. Disable Enhanced Device Support - Rewired Input Manager -> Settings -> Enhanced Device Support. Press Play.
    3. Disable Native Mouse Handling - Rewired Input Manager -> Settings -> Native Mouse Handling. Press Play.
    4. Disable Native Keyboard Handling - Rewired Input Manager -> Settings -> Native Keyboard Handling. Press Play.
    5. Switch to Direct Input - Rewired Input Manager -> Settings -> Primary Input Source. Press Play.
    6. Switch to Unity Input - Rewired Input Manager -> Settings -> Primary Input Source. Press Play.

    Tell me at which point it starts working.

    Rewired U5 is not compatible with Unity 2017. There is a Unity 2017 version of Rewired on the Asset Store which will be downloaded if you download it with Unity 2017.
     
  29. utkarshdwivedi3997

    utkarshdwivedi3997

    Joined:
    Aug 11, 2017
    Posts:
    18
    @guavaman
    It started working when I switched to Direct Input. Thanks so much!

    Okay, thanks for letting me know! For the record, I've switched back to Unity 5.6.0f3, and as mentioned, switching to Direct Input seems to work for me.
     
  30. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    Actually, I wasn't suggesting you switch to Direct Input as a solution. I was asking you to go through those steps so I could narrow down where the issue might lie. Disabling none of the other options made any difference? Then it must be some device, real or virtual, on your system causing it. I will need you to follow up privately so I can work with you to find out exactly where and what the problem is and how to come up with a workaround.
     
  31. AmbroiseRabier

    AmbroiseRabier

    Joined:
    Dec 4, 2016
    Posts:
    12
    Hello there, I have a question. I'm trying to use AddInputEventDelegate but I don't understand something.

    Code (CSharp):
    1.         rewiredController.player.AddInputEventDelegate(onCamera1, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, RewiredConsts.Action.Strategist.CAMERA1, new object[]{1});
    2.  
    http://guavaman.com/projects/rewire.../M_Rewired_Player_AddInputEventDelegate_1.htm

    I dont see how I can get the 'new object[]{1}' argument in the callback method. I supposed it was inside 'InputActionEventData', like 'myInputActionEventData.additionnalArguments' but no.

    Just to be clear, what I'm trying to achieve is to transform this:
    Code (CSharp):
    1.  
    2.         rewiredController.player.AddInputEventDelegate(onCamera1, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, RewiredConsts.Action.Strategist.CAMERA1);
    3.         rewiredController.player.AddInputEventDelegate(onCamera2, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, RewiredConsts.Action.Strategist.CAMERA2);
    4.         rewiredController.player.AddInputEventDelegate(onCamera3, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, RewiredConsts.Action.Strategist.CAMERA3);
    into this:
    Code (CSharp):
    1.  
    2.         rewiredController.player.AddInputEventDelegate(onCamera, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, RewiredConsts.Action.Strategist.CAMERA1, new object[]{1});
    3.         rewiredController.player.AddInputEventDelegate(onCamera, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, RewiredConsts.Action.Strategist.CAMERA2,  new object[]{2});
    4.         rewiredController.player.AddInputEventDelegate(onCamera, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, RewiredConsts.Action.Strategist.CAMERA3,  new object[]{3});

    I am misunderstanding the use of this last argument in AddInputEventDelegate or I am missing something ?

    Thank you for reading.
     
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    The arguments are not for passing objects into the callback. From the docs:
    http://guavaman.com/projects/rewire.../M_Rewired_Player_AddInputEventDelegate_4.htm

    arguments - Arguments for the event. See InputActionEventType for event types that require arguments.

    If you look at InputActionEventType, you'll see a few of them have optional arguments like ButtonJustDoublePressed. The argument lets you set the double press timing. Same with short/long press. There is no object argument to pass in your own arguments to the callback.
     
    AmbroiseRabier likes this.
  33. kenlem1

    kenlem1

    Joined:
    Mar 20, 2014
    Posts:
    22
    I'm working on a FPS project for desktop and mobile. Now, I need a "Swipe to Look" type control on the screen instead of normal analog joystick. I've tried a Touch Pad with delta motion but that gives really odd, jerky results which I kind of understand why since it's just returning raw values. Is there an example anywhere of using Rewired for a nice, smooth Swipe to Look control?
     
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    If set to pixel delta, it returns a delta value exactly like a mouse and will work for rotating a camera. You must be processing the value in an incorrect way. The Rewired/Extras/TouchControls/Examples/TouchControls1 includes swipe to rotate the cube. Rewired does not include any look rotation scripts or otherwise post-processing for input values. Use any look rotation script that was written to read mouse values. Also, do not attempt to get this value in Fixed Update.
     
    Last edited: Nov 2, 2017
  35. AmbroiseRabier

    AmbroiseRabier

    Joined:
    Dec 4, 2016
    Posts:
    12
    Thank for you reply at my first question Guavaman.
    I'll have another one.

    Code (CSharp):
    1. rewiredController.player.AddInputEventDelegate((p) => { onInteractOrder.Invoke(); }, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, RewiredConsts.Action.Strategist.INTERACTORDER);
    2.  
    In this code, if something happen in any callback to onInteractOrder delegate I get this error:

    It's it not possible to have the usual unity error, that would give me the line of the error in the callback function ? (this is rather painful for debugging)
     
  36. kenlem1

    kenlem1

    Joined:
    Mar 20, 2014
    Posts:
    22
    Thanks for the response. Your example works perfectly. I'm still having trouble as my values seem to be calibrated (-1 to 1) instead of like mouse coordinates even though I have calibrate turned off. There must be something else I'm missing.
     
  37. LunaTrap

    LunaTrap

    Joined:
    Apr 10, 2015
    Posts:
    107
  38. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    Look at the rest of what is logged that appears below what you have posted here. The entire exception is logged there. It should include line numbers if they were included in the exception. There is no way I can modify what information is contained in this exception. There is also no way I can make double clicking this log entry take you to the problem in your code. I have to catch the exception that occurs in the callback or else Rewired will completely fail and no longer function when your code throws an exception.
     
  39. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    Last edited: Nov 3, 2017
  41. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    4,617
    Using the "Rewired Event System" processes UI events, even if the application has no focus, as shown in the video below.



    If the game runs in full screen mode and the user Alt+Tab's to another application, Rewired continues to trigger "Pointer Enter" and "Pointer Exit" events in the game, even though the game window has no focus. In our game, it causes sounds to trigger in the background.

    Using Unity's Event System does not trigger these events if the application has no focus, this is the expected behavior.

    I'm using Rewired 1.1.5.3.U2017.
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    Looking at the source code, Unity (again) changed something in the StandaloneInputModule source code. They seem to make changes in almost every version of Unity. This is a constantly moving target. The source code is not released except on major Unity versions, usually a very long time after the new version has been released.

    The expected behavior was not the default behavior until some point after Unity 5.6 based on the following source code. The change only appears in the source code 2017.1:

    Unity 5.6 StandaloneInputModule souce code:
    https://bitbucket.org/Unity-Technol...Module.cs?at=5.6&fileviewer=file-view-default

    Unity 2017.1 StandaloneInputModule source code:
    https://bitbucket.org/Unity-Technol...ule.cs?at=2017.1&fileviewer=file-view-default

    UpdateModule, ActivateModule, and Process all get the new code:
    Code (csharp):
    1. if (!eventSystem.isFocused && ShouldIgnoreEventsOnNoFocus())
    2.                 return;
    They added the function:
    Code (csharp):
    1. private bool ShouldIgnoreEventsOnNoFocus()
    2.         {
    3.             switch (SystemInfo.operatingSystemFamily)
    4.             {
    5.                 case OperatingSystemFamily.Windows:
    6.                 case OperatingSystemFamily.Linux:
    7.                 case OperatingSystemFamily.MacOSX:
    8. #if UNITY_EDITOR
    9.                     if (UnityEditor.EditorApplication.isRemoteConnected)
    10.                         return false;
    11. #endif
    12.                     return true;
    13.                 default:
    14.                     return false;
    15.             }
    16.         }
    Rewired supports versions of Unity from 4.3 onwards. EventSystem.isFocused and SystemInfo.operatingSystemFamily do not exist in Unity 5.0, so this code cannot be copied and pasted into the RewiredStandaloneInputModule.

    Make the following changes to Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs:

    Code (csharp):
    1. //Line 149, add:
    2. private bool m_HasFocus = true;
    3.  
    4. //Line 306, add:
    5. if(!m_HasFocus && ShouldIgnoreEventsOnNoFocus()) return;
    6.  
    7. //Line 362, add:
    8. if(!m_HasFocus && ShouldIgnoreEventsOnNoFocus()) return;
    9.  
    10. //Line 386, add:
    11. if(!m_HasFocus && ShouldIgnoreEventsOnNoFocus()) return;
    12.  
    13. // Line 811, add:
    14. protected virtual void OnApplicationFocus(bool hasFocus) {
    15.     m_HasFocus = hasFocus;
    16. }
    17.  
    18. private bool ShouldIgnoreEventsOnNoFocus() {
    19. #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX || UNITY_WSA || UNITY_WINRT
    20. #if UNITY_EDITOR
    21.     if(UnityEditor.EditorApplication.isRemoteConnected) return false;
    22. #endif
    23.     if(!ReInput.isReady) return true;
    24. #else
    25.     if(!ReInput.isReady) return false;
    26. #endif
    27.     return ReInput.configuration.ignoreInputWhenAppNotInFocus;
    28. }
    29.  
    30.  
     
  43. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    4,617
    Can't you put this in a #if UNITY_<VERSION>_OR_NEWER block?

    Are you going to add this to the next update too?
    I don't like the idea of me changing the Rewired code, because it will cause issues or additional work when I update Rewired.
     
  44. Amalfi-Prozen

    Amalfi-Prozen

    Joined:
    Feb 2, 2014
    Posts:
    29
    Hi, I want to control mouse via joystick 360 (with its axis). How I can do?
     
  45. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    There's no point. The code does the same thing and works fully on all versions of Unity. EventSystem.isFocused is nothing more than a variable set when OnApplicationFocus() is called on the EventSystem component.

    #if UNITY_<VERSION>_OR_NEWER was added in Unity 5.3. No version prior has this option. And I do not know exactly what Unity version added those two values.

    Yes.
     
    Last edited: Nov 4, 2017
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    Rewired does not allow setting the position of the OS mouse cursor on any platform. You would have to hide the OS cursor and make your own substitute mouse cursor using a 2D or 3D object and moving it with player.GetAxis. This 2D/3D cursor would not interact with Unity UI components unless you change the StandaloneInputModule to get the mouse pointer position from your cursor instead.
     
  47. S_Darkwell

    S_Darkwell

    Joined:
    Oct 20, 2013
    Posts:
    318
    On@guavaman:

    Good afternoon!

    I am receiving the following error:
    Rewired: Rewired: Rewired is not initialized. Do you have a Rewired Input Manager in the scene and enabled?
    ------- Rewired System Info -------
    Unity version: 2017.3.0b8
    Rewired version: 1.1.7.8.U2017
    Platform: Unknown
    Using Unity input: False

    UnityEngine.Logger:LogError(String, Object)
    Rewired.Logger:LogErrorNow(Object, Boolean)
    Rewired.Logger:LogError(Object, Boolean)
    Rewired.Logger:LogError(Object)
    Rewired.ReInput:JohgbnfiFLDZPQEPSxqtebqRyAkc()
    Rewired.ReInput:get_players()
    PlayerCameraInput:SetInputId(Int32) (at Assets/_Game/Scripts/PlayerCameraInput.cs:45)
    MyPlayer:OnValidate() (at Assets/_Game/Scripts/MyPlayer.cs:77)

    I have a MonoBehavior OnValidate() function calling "ReInput.players.GetPlayer" if a change occurs in the inspector at runtime. This error only occurs when the game first starts; thereafter, I can chance the inspector value without issue.

    I've confirmed that Rewired's Script Execution Order is correct (it is, there are no other scripts with a custom order, and I ran "Window>Rewired>Setup>Run Installer" anyways just in case). Also, Rewired Input Manager exists and is enabled in the scene and is not being instantiated at runtime.
     
  48. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    OnValidate runs before Awake when you start Play mode in the editor because Unity deserializes all the values at that time. Your script is calling Rewired functions before Rewired has been initialized. Use ReInput.isReady before calling anything in the Rewired API.
     
    Last edited: Nov 5, 2017
    S_Darkwell likes this.
  49. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    57
    I am having this error, even after reinstalling Rewired from scratch:

    I checked that the said framework was on my Mac at /System/Library/Frameworks/IOKit.framework, but maybe it requires it as a dll for mono? The project was compiling fine a few changes earlier, and my changes dealt with debug methods only. I'm not sure I had exactly this error after my changes, but I definitely have it after reinstalling Rewired.

    My other project using Rewired is fine.
     
  50. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    4,010
    http://guavaman.com/projects/rewired/docs/KnownIssues.html#osx-net46-initialization-exception

    Disable .Net 4.6 experimental back end. It cannot work on OSX until they fix this bug.
     
unityunity