- Home /
Access Magnetometer Compass values via Unity Remote 4 for Android
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 instead 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'm using Unity 5.2.1f1
I also set the permissions in the start function: void Start() { Input.location.Start(); Input.compass.enabled = true; Input.gyro.enabled = true; } void OnGUI() { GUILayout.Label("rawVector_z: " + Input.compass.rawVector.z); }
Related issues I found:
http://answers.unity3d.com/questions/843516/compass-returns-all-zeros.html
http://feedback.unity3d.com/suggestions/unity-remote-compass-values
Steps to reproduce it:
Create empty GameObject
Create C#-Script and attach it to the GameObject
Paste the following code: (adjust class name)
using UnityEngine; using System.Collections;
public class getCompassValues : MonoBehaviour {
public float gyro_value;
public float compass_value;
// Use this for initialization
void Start () {
Input.location.Start();
Input.compass.enabled = true;
Input.gyro.enabled = true;
}
// Update is called once per frame
void Update () {
gyro_value = Input.gyro.rotationRate.y;
compass_value = Input.compass.rawVector.z;
}
void OnGUI()
{
GUILayout.Label("rawVector_z: " + Input.compass.rawVector.z);
GUILayout.Label("Gyroscope z: " + Input.gyro.rotationRate.z);
}
}
Get Unity Remote 4 for Android. Enable Unity Remote on your PC via Edit->Project Settings->Editor: Under Unity Remote choose "Any Android Device" in the first row.
Connect the Android Device via USB, start the Remote App and press Play.
You should see the gyrovalues over the GUI and also over variable in the editor, but the compass value is always zero. Sometimes the gyro value is also 0, then stop and press play again.
Thanks! regards Simon
Hello Simon,
How did you get on with this project? I am a 3rd year game sound student and am ai$$anonymous$$g to use compass data in a binaural action game I am creating. It would be great to perhaps get some insight into your progress with this to see if you may be able to offer some help with my compass integration.
Thanks,
Patrick
Your answer
![](https://koobas.hobune.stream/wayback/20220612041237im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why I can not enable compass (I gave it time to warm-up)? 0 Answers
How do I find out anything about the Unity Remote for Android that is available in Unity 3.2? 1 Answer
Sensor Fusion of Accelerometer and Gyroscope 0 Answers
Android Testing 4 Answers
Mapping Android Media Key Codes To Unity 2 Answers