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,633
    Look at the Controller class used in the code you posted. It has all kinds of functions that can be used for getting all kinds of information like this.
     
    Meowx likes this.
  2. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    I am having issues with Rewired not recognizing the Logitech F310 (X) with the controller switch set to X.

    Rewired works fine and recognizes all my other controllers (steering, flight etc) by the correct controller template name.

    This is the first time I've tested with a gamepad. I bought a new F310.

    If I set the controller switch to X, it still works but only if I have a [T] Gamepad Template setup, and it shows up in control mapper as "XInput Gamepad". It does not use the F310 (X) template which I'm assuming should apply in X mode. When I set the controller switch to D, it shows in control mapper as the "F310" and correctly uses the F310 (D) template that I setup.

    I can still use the F310(X) even without defining a default gamepad template. Control mapper lets me map everything under "Xinput Gamepad".

    This is the only gamepad I have so I can't test any other way.

    I didn't see anything obvious in the docs about it.

    Any suggestions?
     
  3. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    There's a lot in the docs about this issue. It's XInput:
    https://guavaman.com/projects/rewired/docs/ControllerMaps.html#xinput-devices-windows
    https://guavaman.com/projects/rewired/docs/KnownIssues.html#xinput-device-name
    https://guavaman.com/projects/rewired/docs/KnownIssues.html#windows-xinput-devices-use-x360-map
    https://guavaman.com/projects/rewir....html#windows-xbox-one-controller-doesnt-work

    TLDR:
    1) XInput cannot tell the difference between different gamepad controller types. Every gamepad is simply an XInput gamepad.
    2) Rewired maps XInput devices to the Xbox 360 Controller definition on Windows.
    3) Gamepad Template maps to all XInput devices and other supported gamepads.
     
    Last edited: Feb 11, 2021
  4. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    Doh! I totally gaped on searching the Rewired docs. I did try, but I think all the Google ads in the results turned me off so quickly I didn't look further.

    Thanks for linking to the important bits, cheers!
     
  5. Vincent_Stagg

    Vincent_Stagg

    Joined:
    Jul 3, 2019
    Posts:
    13
    Hi i have managed to get the keyboard setup correct but i am having alot of trouble making the mouse work, I cannot get the character/camera to turn left or right and i cannot look up or down, I think it has something to do with the Y and X axis but i have been unable to figure out what i am doing wrong.

    camera.PNG
     
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Troubleshooting - Mouse Input Doesn't Work:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#mouse-problems

    Debug Information: How to find the source of the problem
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information
     
    Vincent_Stagg likes this.
  7. Vincent_Stagg

    Vincent_Stagg

    Joined:
    Jul 3, 2019
    Posts:
    13
  8. QbAnYtO

    QbAnYtO

    Joined:
    Dec 18, 2016
    Posts:
    223
    Hey guavaman, So I was wondering, What if my users who game on a pc use different controllers? forexample, lets say i have this running perfectly on an xbox controller, But another customer uses a ps3 controller on his computer, and another one uses another type of usb gamepad on their computer...

    Will rewired automagically make these work on their respective axis's? Or do I have to create all these profiles for all these possible combinations? How will rewire work with different controllers?

    clearly this should be a problem on consoles as they only use one type of controller, but on PC/Mac, you have different controller options. thanks!
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Providing for a way to map controllers across device types and across platforms is a core functionality of Rewired and one of the primary purpose Rewired exists. I suggest you read the documentation on Controllers and Controller Maps:

    https://guavaman.com/projects/rewired/docs/Controllers.html
    https://guavaman.com/projects/rewired/docs/ControllerMaps.html
    https://guavaman.com/projects/rewired/docs/ControllerTemplates.html
    https://guavaman.com/projects/rewired/docs/SupportedControllers.html

    Everything you are asking about is found in that documentation.

    Rewired doesn't do anything "automagically." It only does what you tell it to do. If you defined your Controller Map for the Gamepad Template, it will apply to all controllers supported by the Gamepad Template as stated in the documentation. Otherwise, if you defined your Controller Map for the Xbox 360 Controller, it will apply only to the Xbox 360 Controller. Any controller a user uses that doesn't match to a pre-defined controller map you made will provide no input and would have to be mapped by the user at runtime.

    See Best Practices for more important information.
     
  10. Srokaaa

    Srokaaa

    Joined:
    Sep 18, 2018
    Posts:
    169
    @guavaman Hey, I have a problem with Script Execution Order after I install ReWired. Whenever I try to add an item (click plus icon) to Script Execution Order I get following error:

    Code (CSharp):
    1. ArgumentException: An item with the same key has already been added. Key: Assets/Rewired/Internal/Libraries/Runtime/Rewired_Core.dll.meta
    2. System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <9577ac7a62ef43179789031239ba8798>:0)
    3. System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <9577ac7a62ef43179789031239ba8798>:0)
    4. UnityEditor.ScriptExecutionOrderInspector.ShowScriptPopup (UnityEngine.Rect r) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/ScriptExecutionOrderInspector.cs:386)
    5. UnityEditor.ScriptExecutionOrderInspector.OnInspectorGUI () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/ScriptExecutionOrderInspector.cs:615)
    6. UnityEditor.AssetSettingsProvider.OnGUI (System.String searchContext) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Settings/Providers/AssetSettingsProvider.cs:92)
    7. UnityEditor.SettingsWindow.DrawControls () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Settings/SettingsWindow.cs:407)
    8. UnityEditor.SettingsWindow.DrawSettingsPanel () (at /Users/bokken/buildslave/unity/build/Editor/Mono/Settings/SettingsWindow.cs:385)
    9. UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:353)
    10. UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:663)
    11. UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:635)
    12. UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:628)
    13. UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUIRaw (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:594)
    14. UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:583)
    15. UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/IMGUIContainer.cs:516)
    16. UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/Events/IEventDispatchingStrategy.cs:113)
    17. UnityEngine.UIElements.MouseEventDispatchingStrategy.SendEventToRegularTarget (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/Events/MouseEventDispatchingStrategy.cs:35)
    18. UnityEngine.UIElements.MouseEventDispatchingStrategy.SendEventToTarget (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/Events/MouseEventDispatchingStrategy.cs:26)
    19. UnityEngine.UIElements.MouseEventDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel iPanel) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/Events/MouseEventDispatchingStrategy.cs:19)
    20. UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/EventDispatcher.cs:373)
    21. UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/EventDispatcher.cs:336)
    22. UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/EventDispatcher.cs:299)
    23. UnityEngine.UIElements.EventDispatcher.OpenGate () (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/EventDispatcher.cs:264)
    24. UnityEngine.UIElements.EventDispatcherGate.Dispose () (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/EventDispatcher.cs:75)
    25. UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/EventDispatcher.cs:364)
    26. UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/EventDispatcher.cs:216)
    27. UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/Panel.cs:371)
    28. UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/UIElementsUtility.cs:461)
    29. UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/UIElementsUtility.cs:209)
    30. UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/UIElementsUtility.cs:74)
    31. UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Core/UIElementsUtility.cs:28)
    32. UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)
    33.  
    upload_2021-2-16_10-8-0.png upload_2021-2-16_10-8-0.png
     
  11. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    That is Unity throwing the exception, not Rewired. I can't fix it:
    Unity Issue Tracker - Impossible to add a Script to Execution Order when an Asset containing &#39;dll.meta&#39; files is imported (unity3d.com)
     
  12. Toficor

    Toficor

    Joined:
    May 6, 2015
    Posts:
    33
    I have very wierd situation. I have maped action to controller element like in the attached screenshot,
    rewired.PNG

    and my Rewired Standalone Input Module looks like second screenshot. Everything works fine when I use thumbstick, unlike to D-pad. Although I have thesame data in the Input Manager -> Debug Information.

    input.PNG

    My UI elements are just simple buttons.
     
  13. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    There's nothing I know of that could possibly cause D-Pad to not work if analog stick works unless your D-Pad mappings are not actually loaded in your Player or are disabled.

    Use the checklist here to step through everything live and find out what the problem is. Of particular importance is the Action value of UIVertical and UIHorizontal. If those are producing no value when press the D-Pad, you can be certain your mappings are not loaded or are not enabled. If they are, then the D-Pad is not working period. This checklist will lead you to that result if that's the case:
    https://guavaman.com/projects/rewir...l#debug-information-diagnosing-input-problems
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Rewired 1.1.38.3 is available on the Unity Asset Store:

    1.1.38.3:

    Changes:
    - Updated Universal Fighting Engine 2 integration to fix issues caused by changes in UFE2 since last update.
    - RewiredEventSystem script execution order is now automatically set to -1000.

    Bug Fixes:
    - Editor script now enables building to Game Core platforms in Rewired_Core.dll.
     
  15. aeonphyxius

    aeonphyxius

    Joined:
    Jun 16, 2013
    Posts:
    13
    Hi there @guavaman

    I am getting the following error:
    Rewired_Core11.cpp(22804) : fatal error C1001: Internal compiler error.

    While compiling a Unity project in the following

    Unity 2019.4.20f1
    Windows 64bits platform
    Windows 10 PC
    Visual Studio 2019

    I saw that there was a similar problem in Unity 2018, could this be related?

    Thanks !
     
  16. aeonphyxius

    aeonphyxius

    Joined:
    Jun 16, 2013
    Posts:
    13
    As a heads up, I solved this problem by rolling back to VS2017
     
  17. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    See the big notice at the top of the documentation page:
    https://guavaman.com/projects/rewired/docs/KnownIssues.html#windows-standalone-il2cpp-vs2019-hang

    This affects all versions of Rewired. Switching to Unity 2017 does not fix it, it only changes the manifestations of the issue as these are totally random and change with every Rewired build. You will not have a proper IL2CPP build using Visual Studio 2019 unless you disable the jump optimizer on any version of Unity when using any version of Rewired.
     
  18. Valax321

    Valax321

    Joined:
    Sep 29, 2017
    Posts:
    3
    Hi there,

    I'm having an issue building projects for UWP using il2cpp on (at least) unity 2020.2.4 and 2020.2.6. The build makes it to the converting managed code to C++ stage before stopping with the following callstack:

    Code (CSharp):
    1. Exception: IL2CPP error (no further information about what managed code was being converted is available)
    2. System.NullReferenceException: Object reference not set to an instance of an object.
    3.    at Unity.IL2CPP.Extensions.ModuleInitializerMethod(AssemblyDefinition assembly)
    4.    at Unity.IL2CPP.Metadata.PerAssemblyCodeMetadataWriter.Write(SourceWritingContext context, AssemblyDefinition assembly, GenericContextCollection genericContextCollection, String assemblyMetadataRegistrationVarName, String codeRegistrationVarName)
    5.    at Unity.IL2CPP.AssemblyConversion.SecondaryWrite.Steps.PerAssembly.WritePerAssemblyCodeMetadata.ProcessItem(GlobalWriteContext context, AssemblyDefinition item)
    6.    at Unity.IL2CPP.AssemblyConversion.Steps.Base.ScheduledItemsStepFuncWithContinueAction`3.WorkerWrapper(WorkItemData`3 workerData)
    7.    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.ContinueWithResultsWorkItem`4.InvokeWorker(Object context, Int32 uniqueId)
    8.    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.BaseContinueWorkItem`2.Invoke(Object context, Int32 uniqueId)
    9.    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data)
    10. UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at <8c48e4bc2ff34638b69095cbb65e2e27>:0)
    11. ...
    (Removed the rest of the callstack to prevent spam, isn't relevant)

    I've been able to reproduce this in my own game and a fresh 3d template project with only rewired added (UWP platform support installed).

    I'm using the latest 2020 Rewired version from the Asset Store (just came out a few days ago)

    Seems like it's either a weird bug or my computer simply hating me. Any idea what's going on? Thanks for the help!
     
    Last edited: Feb 24, 2021
  19. galvanizingart

    galvanizingart

    Joined:
    Apr 25, 2017
    Posts:
    1
    @guavaman - is this solved in latest Rewired update? I still get this issue where my controllers gets disconnected event call without being physically disconnected if any new controller is connected. Any way i can fix this? or atleast identify controllers uniquely to reassign it to right player?

     
  20. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    No because this was never a problem with Rewired. It's Unity or the underlying native API. You can see this in my replies to his message:
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-112#post-4939565
    https://forum.unity.com/threads/rewired-advanced-input-for-unity.270693/page-112#post-4947491

    Rewired is 100% dependent on UnityEngine.Input for all input on iOS/tvOS. Any possible fix for this would have to come in the form of entirely replacing UnityEngine.Input with a native library. Even that may not fix it if the problem is in the underlying API. The list of platforms and how they implement input is here:
    https://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms.
     
  21. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    All IL2CPP errors on Windows are caused by the same Visual Studio 2019 bug.

    See the notice at the top of the documentation:
    https://guavaman.com/projects/rewired/docs/

    Visual Studio 2019 -- All platforms compiled with IL2CPP on Windows: Builds never finish, build fails with errors, builds crash, built exe hangs at launch, or builds throw exceptions about duplicate Actions
     
  22. Valax321

    Valax321

    Joined:
    Sep 29, 2017
    Posts:
    3
    Oh yeah I didn't mention that I already installed the compiler flag fix script from that page when I was having this issue, sorry about that. I've verified that the flag is actually added to additionalIl2CppArgs in my empty test project settings as well, and the exact same error occurred when building. So this doesn't directly seem to be the issue...

    I'll give building my project a test on a different PC and see if the same problem occurs.
     
  23. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    I doubt it will help. If that's the case, Unity probably changed something significant under the hood and/or introduced a new show-stopping bug. That's usually the cause of things like this. The only thing you can do is fIle a bug report. The exception is being thrown by IL2CPP itself.
     
    Last edited: Feb 24, 2021
  24. Valax321

    Valax321

    Joined:
    Sep 29, 2017
    Posts:
    3
    Yeah, using a different computer didn't help. I've submitted a bug report with Unity, hopefully something comes of it.
    This issue aside, Rewired is great, keep up the good work :)
     
  25. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    I can confirm the exact same code built by Unity 2020.1.0f1 works, but fails with the error you show in 2020.2.6f1. This is a new Unity error and I can't fix it. It's not the first time Rewired's ability to run under UWP has been completely broken by a Unity update.
     
  26. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    No problem in 2020.1.17f1 either. 2020.2.x branch bug.
     
  27. lamtacla

    lamtacla

    Joined:
    Mar 31, 2019
    Posts:
    12
    Hi guavaman.

    1. Please help me implement this:
    On Mobile device:
    _ if any button/axis from a Real-Controller press, then disable all the Custom-Touch-Controller.
    _ if any touch happen in the screen, then re-enable the Touch-Controller


    2. On your support controller list:
    https://guavaman.com/projects/rewired/docs/SupportedControllers.html
    I see that almost no controller is supported in iOS column.
    But I test my PS4 and my GameSir controller on my iPhone, they work all. So you should change them to "yes, support".
     
  28. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    There are many ways to implement this.

    Detect a button-down on any controller:
    https://guavaman.com/projects/rewir...ReInput_ControllerHelper_GetAnyButtonDown.htm

    Detect a touch:
    https://docs.unity3d.com/ScriptReference/Input-touchCount.html
    https://docs.unity3d.com/ScriptReference/Input.GetTouch.html

    The only controllers I know that are supported on iOS 13+ that were not before are Xbox controllers and Sony DS4. Any others that happen to work are undocumented by Apple. My list of controllers doesn't specify iOS versions, therefore doesn't only include iOS 13+, and these controllers are not supported on any version prior to iOS 13.
     
  29. lamtacla

    lamtacla

    Joined:
    Mar 31, 2019
    Posts:
    12
    @guavaman: thank you.
    ControllerHelper.GetAnyButtonDown(ControllerType) work perfect for me.

    By the way is there any method like: bool ControllerHelper.GetAnyAXIS(ControllerType) ?
    I want to catch Axis, too. But GetAnyButtonDown() not work for Axis.
     
  30. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Hi

    I´m having issues running rewired on a mac for a project compiled for ios. As you may know, now when you upload a package for iphone, a mac can download that game and run it on the computer. All good, except that on the computer, it needs to use the keyboard and controllers and so far I can´t get it to work with rewired. It still thinks is running on an ios device.

    Any ideas?
     
  31. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    No. ReInput.ControllerHelper is a convenience class that has a few functions that iterate over all controllers for the most common uses. It does not provide functions that apply to all controllers for every single function that exists in the Controller classes. These functions are nothing more than a loop over controllers of a particular type calling one function. You can easily do the same thing yourself on all controllers or all controllers of a particular type.

    Look through the Joystick class API reference. There are a ton of functions to get all kinds of information you might want:
    https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ControllerWithAxes.htm

    There are functions that give you timestamps and various other information. GetLastTimeActive() is the exact function the built-in last active controller stuff in Rewired uses. https://guavaman.com/projects/rewired/docs/HowTos.html#last-used-controller This itself simply uses the last active time on each button and axis on the controller to determine the last active time of the controller.
     
  32. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Rewired does not have any specific support for iOS apps running on Mac.

    Look at Tested Platforms:
    https://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms

    You will see iOS is a platform that is 100% dependent on UnityEngine.Input for all input. Rewired does not have a single bit of native code on iOS. All keyboard, mouse, and joystick input all come form standard UnityEngine.Input function calls like Input.GetKey. If keyboard isn't working on an iOS app running on Mac, then it's Unity doing it because Rewired does not disable keyboard or mouse input simply because you're running on iOS.

    Your application thinking it is running on iOS is how it is supposed to work. Your application isn't going to become a MacOS application because you run it on MacOS. You made an iOS build and it will always be an iOS application. None of the MacOS code exists in your application.

    I have no idea if Unity supports input on iOS when run on a Mac. With how new all this stuff is, I doubt it.
     
  33. RealityDotStop

    RealityDotStop

    Joined:
    Mar 4, 2013
    Posts:
    42
    Hi guavaman!

    I recently was working with a user on the Bolt (now UnityVS) discord that encountered an issue with the Rewired integration failing to deserialize under IL2CPP backends.

    This sounds very similar to a problem I encountered with the Community Addons, where custom units in a dll are stripped out under AOT platforms, because there isn't any code referencing them. Fortunately, I worked up a solution that I think you can employ, embodied at: RealityStop/Unity.LinkMerge (github.com)

    This is the same solution we're using with the Community Addons to prevent UPM package assemblies from being stripped.
     
    guavaman likes this.
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Thanks for the information and the link to your solution.

    Why would code be getting stripped from a DLL containing custom units that are only referenced by Bolt, but code in other DLLs, for example Rewired_Core.dll, also not referenced from anywhere but Bolt not be stripped? That doesn't sound right.

    I really want to avoid having to include special build scripts, things dependent upon certain versions of Unity (the build interfaces you are using weren't available until 2018.1) , or instructions requiring users to do things with files. More things to go wrong and more things to support.

    I would think some script with a static method that instantiate those classes would be sufficient. Actually, I'd prefer just dropping the Bolt integration. It really provides very little functionality not available in the default Bolt auto-generated API. Just a few events.
     
  35. Zaddo

    Zaddo

    Joined:
    May 19, 2012
    Posts:
    78
    Hi Guavaman, I just tried using rewired for the first time. I am getting stuck on the reported IL2CPP issue. I have the fix to the compiler override applied. FYI, I am using 2020.2.1f1
     
    Last edited: Feb 27, 2021
  36. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    The issue causing this has nothing to do with different versions of Unity. It's entirely due to a bug in Visual Studio 2019 that Microsoft has not fixed in the 9 months since I reported it to them. I cannot do anything to get around this bug. If I were able to do so, I would have done it.

    Rewired is absolutely not unusable. Thousands of developers are using it right now in games and continue to do so as I can attest to based on the number of support emails I have to respond to every day. IL2CPP builds are very common and nobody has ever reported to me any situation that ended in the result they simply could not make a build except in the case of critical low-level errors by Unity that I have absolutely no way to work around such as the new UWP Unity bug and the Mac Silicon Mono build bug. IL2CPP is required for all console platforms and works on all that are supported.

    I am making IL2CPP builds right now at this very minute on Windows using the latest version of Visual Studio 2019 and Unity 2020.2.6f1. There are no problems when the jump optimizer workaround is applied on the Windows Standalone platform.

    If you want help solving the problem, I need more information:
    1. What version of Rewired.
    2. What build target.
    3. What version of Visual Studio 2019.

    Things to try:
    1. Wait longer than you think you should for the build to finish (5+ minutes).
    2. Try building with nothing but Rewired in the project. Open Examples/EightPlayers and build it.
     
    Last edited: Feb 27, 2021
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    It appears the compiler flag to disable the Visual Studio 2019 jump optimizer doesn't work on the Xbox One build target (XDK, not Game Core), so I've updated the script to remove it from the list of build targets.
     
  38. Zaddo

    Zaddo

    Joined:
    May 19, 2012
    Posts:
    78
    HI Guavaman. Apologies, I didn't intend to come across as combative. I just wanted to warn others of the issue. All your points are valid. I edited my post so as not to mislead anyone.

    I have to keep moving forward with my project, so I am just going to make do with Unity's Input System. But I thought I would give you a little more info, hopefully it helps.

    I tested with a new project with just Rewired installed and fix applied. It hangs on compile. Screen Capture is at 10 minutes. But I let it run for 45 minutes and no progress.

    Environment:
    Rewired: 1.1.38.3
    Unity: v2020.2.1f1, URP, 64Bit, IL2CPP, .Net4., Windows Build
    Visual Studio: 2019 16.8.5.
    Desktop: See Screen capture
     

    Attached Files:

    Last edited: Feb 27, 2021
  39. RealityDotStop

    RealityDotStop

    Joined:
    Mar 4, 2013
    Posts:
    42

    If there's anything at all in the DLL that Unity thinks is in use, it'll include it in the build. The problem with Bolt integrations is that it's all done via reflection, and there isn't any trail that Unity understands Since the reflection information is just in serialized JSON, Unity thinks it's just a junk DLL.

    And absolutely, this is just one of the options. For us, it was a brain-dead drop-in solution, since modern Bolt requires 2018 anyway and it avoided requiring anything of users. But it's not the only way. As you mention, even a single line of code that references the DLL will convince Unity to include it.


    I just though I recognized the symptoms, and knew I had a potential solution
     
    guavaman and Zaddo like this.
  40. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Thanks for the information.

    I have just done the test with the following:
    Windows 10 19041
    Rewired 1.1.38.3
    Unity 2020.2.1f1
    Visual Studio 2019 16.8.6
    Installed DisableNewVS2019Optimizer.cs
    Windows Standalone build, 64 Bit, IL2CPP, .Net 4

    Built Rewired/Examples/ControlRemapping1/ControlRemapping1 scene.
    Succeeded within 1 minute 45 seconds.

    Identical code and binaries that compile on one machine should compile on another machine with the exact same settings and compiler. That leads me to believe something else is going on here. The only difference I see in our setups is the Visual Studio version, but I highly doubt that would make any difference.

    Could you upload the entire empty project with nothing but Rewired in it to Dropbox or something similar so I could download it and try building it myself? You can PM the link to me if you want.

    Edit:
    I just made a build of the default new URP project in Unity 2020.2.1f1, added Rewired from Package Manager, added DisableNewVS2019Optimizer.cs, Windows Standalone, 64-bit, IL2CPP, .Net 4. Build completed successfully in a few minutes.
     
    Last edited: Feb 27, 2021
  41. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Thanks for posting your solution. I didn't even know this was a stripping issue, so even if I don't end up using the solution, at least I can investigate possible solutions.

    I understand how Unity strips code, but I'm questioning why some code in Rewired_Core that is only ever referenced from Bolt (reflection) wouldn't get stripped but custom units would. Neither are ever referenced from code, yet only one fails. That's the part that doesn't make sense. It seems like something isn't working as it should with their stripping.

    I looked at the source code to my custom unit library and every single class already has the [Preserve] attribute. According to the docs, this should prevent the classes from being stripped:
    https://docs.unity3d.com/ScriptReference/Scripting.PreserveAttribute.html
     
    Last edited: Feb 27, 2021
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    @RealityDotStop

    Okay, here's the answer to my confusion.

    Bolt will generate static stubs when you do AOT prebuild for all the classes referenced by the Macros in your project. This is how it is able to prevent stripping of classes in Rewired_Core.dll. It appears that it DOES NOT generate these stubs for custom Units. It's definitely not doing it for mine. My guess is that Bolt won't generate AOT stubs for anything that inherits from its own classes because they prevent stripping of those classes with the included link.xml file that references all their DLLs, so they're just skipping them. So I would call this an oversight in their AOT pre-compile logic.

    However, there's also something else going on in my case. Using a link.xml that excludes the entire assembly does solve the problem, however, it should also be solvable by using the [Preserve] attribute. Now I added [Preserve] on every single function, constructor, field, property, etc. Still fails. So Unity's stripping is failing to respect the [Preserve] attribute now. I'm guessing this is another new Unity bug, because before now I never had a single person complain that Rewired's Bolt integration failed to compile on any platform. It would have been very obvious because all platforms except desktops now require IL2CPP which is AOT. Perhaps the entire DLL is no longer being included?

    I've tested 2020.1.0f1 and it also fails, so I don't know when this happened, but it looks like there's no possible solution other than to use link.xml to exclude the DLL from stripping.
     
    Last edited: Feb 28, 2021
  43. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    @RealityDotStop

    Yep. It was stripping the DLL entirely because no code was referencing it. The [Preserve] attributes in the DLL were useless because the whole DLL was being excluded. Adding this to a script along with the [Preserve] attributes within the DLL solved it:

    Code (csharp):
    1. namespace Rewired.Integration.Bolt {
    2.     [UnityEngine.Scripting.Preserve]
    3.     internal static class PreventDllStripping {
    4.         [UnityEngine.Scripting.Preserve]
    5.         private static void Preserve() {
    6.             Rewired.Integration.Bolt.Stripping.Preserve();
    7.         }
    8.     }
    9. }
    This static stub just calls into the DLL just to make sure the DLL stays referenced. Then the [Preserve] attributes on all the classes inside the DLL prevent them from being stripped. This solution doesn't require any link.xml files.

    Thanks for your help!
     
    Last edited: Feb 28, 2021
    RealityDotStop likes this.
  44. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    For anyone having trouble with the Bolt integration, I'm posting an update to it here. It will be included in the next update to Rewired, but that may not be for a while.
     

    Attached Files:

    Jmonroe likes this.
  45. Zaddo

    Zaddo

    Joined:
    May 19, 2012
    Posts:
    78
    I tried another build before uploading. This time it succeeded... I didn't change anything in the project, except reload it. The only theory I can think of, is: The ProjectSettings.asset file changes as soon as you add the fix program to the project, which I confirmed had updated before running the first build. Perhaps the compiler overrides require a restart of the editor before the build picks these up?
     
  46. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Thanks for the info. I've tried to replicate the issue and I just can't get it to fail. I've tried starting new projects 5 or 6 times, each trying different sequences of changing to x64, IL2CPP, installing Rewired, and installing the VS patch. No time was the editor closed or any files saved before doing a build. I can't make it fail. So something weird has to be happening with Unity or Visual Studio. I'd suspect Unity before VS since it is responsible for adding that compiler flag to the IL2CPP command line. Unless IL2CPP fails with a crash, there's no way to actually see the command line that I know of. I hope the issue doesn't happen to you again. And I hope Microsoft decides to fix this bug soon.
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    It could also be caching. Unity builds an IL2CPP cache every time you make a build. It's stored in the Library folder of your project. There are usually 2 folders there with cached build data.

    Also, I think if you build the project to a VS project instead of a direct to exe build, Unity won't change the build flags in the VS project if it already exists when you build. At least that's what I saw many months ago.
     
    Zaddo likes this.
  48. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Are you sure about this that you have no "#if" in your code? I've just tested using
    return player.GetAxis((int)ActionIds.MoveHorizontal);
    which is my rewired for getting the cursor keys for left and right... and returned zero.
    while using Input.GetKey did return values running the iOS app on mac.

    meanwhile if i run directly building for mac/pc, it works just fine.
     
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    Yes, I'm sure.

    Check your Disable Keyboard setting on iOS:
    https://guavaman.com/projects/rewired/docs/RewiredEditor.html#Settings

    Check the runtime enabled state of the keyboard:
    Code (csharp):
    1. Debug.Log(ReInput.controllers.Keyboard.enabled);
    Check if the Keyboard is assigned to the Player:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information

    Check Keyboard maps in the Player at runtime:
    https://guavaman.com/projects/rewired/docs/Troubleshooting.html#debug-information

    You can also use that to watch the value of the keys themselves in Debug Information or log:
    Code (csharp):
    1. Debug.Log(ReInput.controllers.Keyboard.GetKey(KeyCode.A));

    It's also possible Unity is not properly reporting application focus events, therefore all input is being blocked because Rewired has no way of knowing the application is in focus.


    On another note, it appears you're using enums for your Action Ids based on the int cast I see. Rewired has a tool for exporting constants to integers that is easier to use than manually making lists of enums:
    https://guavaman.com/projects/rewired/docs/HowTos.html#exporting-constants
     
    Last edited: Mar 1, 2021
  50. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Checking it in a few hours. High chances it was the "disable keyboard" option on ios settings. I'll keep you posted when I manage to build a release.