PatHightree / SpaceNavigator

SpaceNavigator driver for Unity3D
MIT License
170 stars 55 forks source link

SpaceNavigatorHID.current.Rotation.ReadValue() returns 0 0 0 in build version #44

Open Georodin opened 2 years ago

Georodin commented 2 years ago

Describe the bug SpaceNavigatorHID.current.Rotation.ReadValue(); returns in Standalone build only Vector3(0, 0, 0); When use in GameMode it works fine. Also SpaceNavigatorHID.current.Translation.ReadValue(); still returns all values in all modes just rotation returns zero values using the 3Dconnexion wireless version in Unity 2020.3.5f1 using SpaceNavigator-2.0.0-beta.7

To Reproduce Steps to reproduce the behavior:

  1. create new HDRP project in Unity 2020.3.5f1
  2. copy the SpaceNavigator-2.0.0-beta.7 folder to the packages folder
  3. accept the prompt to change to the New Input System
  4. after restart add a script to the camera to vizualize the movement of SpaceNavigatorHID.current.Rotation.ReadValue();
  5. Debug.Log both SpaceNavigatorHID.current.Rotation.ReadValue(); and SpaceNavigatorHID.current.Translation.ReadValue();
  6. try it in GameMode, it does work normal
  7. build the project
  8. in the builded project only SpaceNavigatorHID.current.Translation.ReadValue(); returns values while SpaceNavigatorHID.current.Rotation.ReadValue(); only returns Vector3(0, 0, 0); constantly

Expected behavior SpaceNavigatorHID.current.Rotation.ReadValue(); should return values other than zero in builded versions

Details (please complete the following information):

Additional context Add any other context about the problem here.

Georodin commented 2 years ago
        void Start()
        {
            Type wireless = typeof(SpaceNavigatorWirelessHID);
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(wireless.TypeHandle);

            Type wired = typeof(SpaceNavigatorHID);
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(wired.TypeHandle);
            Debug.Log("Called static");
        }

I added this manual static constructor call to my Camera script and at least the SMW works now in build mode but when I connect it via wire it again ignores the rotation axis but this time everywhere not only in the build

JackeyC commented 2 years ago

I am having the same issue too

nilmother commented 2 years ago

Hi Georodin,

I am pretty new to programming and tried to implement your solution for making the Wireless Spacemouse work in BuildMode. However I am struggling with the script, the "Type" wireless is screaming at me.. Could you provide more information about how to implement your solution? I and my architecture studies would be deeply grateful. Thanks

Georodin commented 2 years ago

Hihi nilmother, so that your script can use the Type thingy you need

using System;
using System.Reflection;

these both at the top of you script those are called namespaces and tell the compiler where to look for Type because sometimes you can have ambiguity within names

and the only thing im doing is finding the constructor of the SpaceNavigatorWirelessHID and call it manually because it's not called automatically but the then constructed Object is needed to get Inputs from the SpaceNavigator

if it's something else, then let me know

nilmother commented 2 years ago

Dear Georodin, it works, thank you so much!!!