Compass returns all zeros
I have no idea why but my compass does not work no matter what I try. Here is my exact code in boo with almost all of the compass methods being printed to the console.
import UnityEngine
class Compass (MonoBehaviour):
def Start ():
Input.compass.enabled = true
Input.location.Start()
def Update ():
rawHeading = Input.compass.rawVector
trueHeading = Input.compass.trueHeading
magneticHeading = Input.compass.magneticHeading
headingAccuracy = Input.compass.headingAccuracy
Debug.Log([rawHeading,trueHeading,magneticHeading,headingAccuracy])
When I run this I get this printed to the console exactly
[(0.0, 0.0, 0.0), 0, 0, 0]
UnityEngine.Debug:Log(Object)
Compass:Update() (at Assets/Compass.boo:15)
I've enabled the compass and started location in the start method, to my understanding, it should work.
My phone is the Droid MAXX, Android version 4.4.4. The compass works on the phone, I've tested through multiple compass apps. There is probably something simple I am missing but I just can't seem to catch it.
Answer by KMKxJOEY1 · Nov 29, 2014 at 09:26 PM
First off, I commend you on your use of boo, not many people utilize the language within Unity. Next thing is, are you testing this using a build or using the Unity Remote? Unfortunately, when developing mobile applications (at least on android), rotation and whatnot has been dodgy for me. Usually I will just make a build and run logcat to get the debug that I need.
I am using the remote. I should of already checked if that's the problem, I will now build it to my device and run it there. I'll get back to you when I get the results.
Yep it seems to work when I build it to my device. That's going to be annoying building it to my device every time I want to test something. I am using Unity 4.6 and Remote 4. I wonder if that's an error in Unity 4.6 or an error with my phone. Any suggestions on how to fix it?
Thanks for that answer. I'm about to start work on a project involving Android, and it's good to know about these problems in advance. :)
Ok great! I agree it is annoying, but other than submitting bug reports there is nothing you can really do to fix it (as far as I am aware). Usually what I do is just add extensive debug so that I can get as much data as I can with each build to $$anonymous$$imize wasted time.
The problem still exists, I reported a bug and writing also here. I'm developing for Android and use the Unity Remote 4 App to interact with the sensors and to see the Game-View immediately on the smartphone. I tested with Samsung Galaxy S3 and Google Nexus 5. If i build and run the application, the compass/magentometer values are accessible. But over the Remote-App the magnetometer values are always 0/not accessible. Building the application all the time ins$$anonymous$$d of using the remote function would take too much time. I checked if other sensor values are accessible. The gyroscope data is shown over the remote app. So it seems to be special problem with the compass sensor.
I also set the permissions in the start function: void Start() { Input.location.Start(); Input.compass.enabled = true; Input.gyro.enabled = true; }
To see the values I used:
void OnGUI() { GUILayout.Label("rawVector_z: " + Input.compass.rawVector.z); }
Related issue I found: - http://feedback.unity3d.com/suggestions/unity-remote-compass-values
Answer by chad47 · Dec 22, 2015 at 09:11 AM
I am having this same problem. I have added ten votes to the issue. If anyone else is having this issue please vote this issue to the top of the list by going to the link that simes89 gave and voting. @byuroccks23 @Joe_User @KMKxJOEY1 @simes89
Answer by DiegoWw · Jul 11, 2019 at 09:41 AM
Same problem here (but only in Unity Remote, at the device it works). I was able to start the LocationService and get GPS readings, but the Compass still return all zeroes (and -1 as the Timestamp).
PS: For anyone not able to even get GPS to work, first enable Location access for the Unity Remote App on the phone itself, on Android configs. It does not automatically ask for permisson in any way.