Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Siggytron · Nov 28, 2020 at 10:44 PM · inputmanagergyroscopesensorambiguous reference

Input System 1.1.0 Resolving ambiguous gyroscope error

Solution: @sacredgeometry pointed out that I needed to write out my reference to the full extent to differentiate the two gyroscopes. While I had tried InputSystem.Gyroscope vs Gyroscope thinking the UnityEngine portion was automatically included, I in fact needed to write it out as UnityEngine.InputSystem.Gyroscope .


Building on a previous script to see what sensors my phone has, I decided to test for all sensors in the new input management system. Full code at bottom. Everything is set up fine except that I get the error message: Error CS0104 'Gyroscope' is an ambiguous reference between 'UnityEngine.InputSystem.Gyroscope' and 'UnityEngine.Gyroscope'
To use the new Input Management System I need to include a using UnityEngine.InputSystem statement. However, I also need the using UnityEngine statement; otherwise, Monobehavior is not recognized. So as far as I know, I need both statements.

I tried to specify in code that the gyroscope I wanted to use was the InputSystem gyroscope by declaring it this way: InputSystem.Gyroscope gyroscope; However, that leads to Error CS0426The type name 'Gyroscope' does not exist in the type 'InputSystem' . Does anyone know how to clear up the ambiguity between gyroscopes when using Input Management System 1.1.0? The user guide does not make any statements about confusion between the two. https://docs.unity3d.com/Packages/com.unity.inputsystem@1.1/manual/Sensors.html https://docs.unity3d.com/Packages/com.unity.inputsystem@1.1/manual/QuickStartGuide.html

 using System.Collections; 
 using System.Collections.Generic; 
 using UnityEngine; 
 using UnityEngine.InputSystem; 
 using TMPro;
     
     public class Sensors : MonoBehaviour {
         public TextMeshPro textaccel;
         public TextMeshPro textgyro;
         public TextMeshPro textgravity;
         public TextMeshPro textattitude;
         public TextMeshPro textlinearaccel;
         public TextMeshPro textmagfield;
         public TextMeshPro textlight;
         public TextMeshPro textpressure;
         public TextMeshPro textproximity;
         public TextMeshPro texthumidity;
         public TextMeshPro texttemp;
         public TextMeshPro textstepcount;
     
         Accelerometer accelerometer;
         InputSystem.Gyroscope gyroscope;
         GravitySensor gravity;
         AttitudeSensor attitude;
         LinearAccelerationSensor linearaccel;
         MagneticFieldSensor magfield;
         LightSensor lightsens;
         PressureSensor pressure;
         HumiditySensor humidity;
         AmbientTemperatureSensor ambient;
         StepCounter step;
     
         void Start()
         {
             accelerometer = Accelerometer.current;
             gyroscope = Gyroscope.current;
             gravity = GravitySensor.current;
             attitude = AttitudeSensor.current;
             linearaccel = LinearAccelerationSensor.current;
             magfield = MagneticFieldSensor.current;
             lightsens = LightSensor.current;
             pressure = PressureSensor.current;
             humidity = HumiditySensor.current;
             ambient = AmbientTemperatureSensor.current;
             step = StepCounter.current;
         }
     
         void Update()
         {
             if (accelerometer != null)
             {
                 InputSystem.EnableDevice(accelerometer);
                 textaccel.text = "enabled";
             }
             else
             {
                 textaccel.text = "null";
     
             }
                   
             if (gyroscope != null)
             {
                 InputSystem.EnableDevice(gyroscope);
                 textgyro.text = "enabled";
             }
             else
             {
                 textgyro.text = "null";
     
             }
     
             if (gravity != null)
             {
                 InputSystem.EnableDevice(gravity);
                 textgravity.text = "enabled";
             }
             else
             {
                 textgravity.text = "null";
     
             }
     
             if (attitude != null)
             {
                 InputSystem.EnableDevice(attitude);
                 textattitude.text = "enabled";
             }
             else
             {
                 textattitude.text = "null";
             }
     
             if (linearaccel != null)
             {
                 InputSystem.EnableDevice(linearaccel);
                 textlinearaccel.text = "enabled";
             }
             else
             {
                 textlinearaccel.text = "null";
     
             }
     
             if (magfield != null)
             {
                 InputSystem.EnableDevice(magfield);
                 textmagfield.text = "enabled";
             }
             else
             {
                 textmagfield.text = "null";
     
             }
     
             if (lightsens != null)
             {
                 InputSystem.EnableDevice(lightsens);
                 textlight.text = "enabled";
             }
             else
             {
                 textlight.text = "null";
             }
     
             if (pressure != null)
             {
                 InputSystem.EnableDevice(pressure);
                 textpressure.text = "enabled";
             }
             else
             {
                 textpressure.text = "null";        
             }
     
             if (humidity != null)
             {
                 InputSystem.EnableDevice(humidity);
                 texthumidity.text = "enabled";
             }
             else
             {
                 texthumidity.text = "null";        
             }
     
             if (ambient != null)
             {
                 InputSystem.EnableDevice(ambient);
             }
             else
             {
                 texttemp.text = "null";
             }
     
             if (step != null)
             {
                 InputSystem.EnableDevice(step);
                 textstepcount.text = "enabled";
             }
             else
             {
                 textstepcount.text = "null";
             }
         } }














Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by sacredgeometry · Nov 29, 2020 at 03:58 AM

When you have an ambiguous reference it means that two types exist with the same name the way to get around this is to just specify the type with the full namespace

i.e.

 UnityEngine.InputSystem.Gyroscope


You could also use an alias to shorten it: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Siggytron · Nov 29, 2020 at 03:32 PM 1
Share

Thanks. That worked. I didn't realize I had to write it ALL the way out. I thought InputSystem.Gyroscope would do it. I had seen that alias article on $$anonymous$$icrosoft's site but since I didn't know how to write it out, I didn't know how I would do the alias. Now it makes sense.

avatar image sacredgeometry Siggytron · Nov 29, 2020 at 03:59 PM 0
Share

Wonderful. I don't suppose you $$anonymous$$d accepting my answer please?

avatar image Siggytron sacredgeometry · Nov 30, 2020 at 03:41 PM 0
Share

I apologize. I upvoted and thought that did it.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

139 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to convert Native Android GyroSensor values (rad/sec) to Quaternion? 1 Answer

Dependency on IMU readings for panorama-like Image capture ? 0 Answers

Sensor Fusion of Accelerometer and Gyroscope 0 Answers

How can I get the phone orientation? 3 Answers

Can Unity WebGL access mobile sensors? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges