googlevr / gvr-unity-sdk

Google VR SDK for Unity
http://developers.google.com/vr/unity/
Other
2.71k stars 1.09k forks source link

Unity 5.2.1f1 & 0.5.2: VRModeEnabled = true does not initialize Head Tracking / Gyro Sensors #105

Closed TamimSha closed 8 years ago

TamimSha commented 9 years ago

When setting Cardboard.SDK.VRModeEnabled = true in code after pressing a button head tracking does not work. However, if you go to the app switcher and resume and the app head tracking will now work. We believe that this is a bug in the SDK.

The reason that we disable VRMode when our app is launched is due to this: http://answers.unity3d.com/questions/997201/unity-ui-not-working-cardboard.html

smdol commented 9 years ago

Does this happen with the demo scene (the red floating cube)? There is a button on the floor that changes VRModeEnabled. Please try this scene because I test this behavior with it and have never seen the problem you report. Can you also say which Distortion Correction mode you are using and if you are changing it?

TamimSha commented 9 years ago

OK. I tried it with the demo and it works. The problem appears when I try to load another scene in Unity using the network manager.

I made a few changes such as not using cardboard in the offline scene or parenting the head prefeb when loading the new scene but no matter what, head tracking doesn't work unless I go to the android home screen and then go back to the app.

Here's the project file: https://drive.google.com/file/d/0Bz_z7dsfEz1tUEh1VFNKeElmRDg/view?usp=sharing

The problem only occurs when running the app on android and it seems to work fine in the editor. To reproduce the problem:

1) Start the app 2) Choose LAN Host(H) on the upper left corner 3) Attempt to use head tracking (Notice it doesn't work!) 4) Go to android home screen. 5) Resume the app. Head tracking should now be working.

thejoebaldwin commented 9 years ago

I have this issue in iOS as well, even if I am in VR mode from the start. If I go profile settings and then back head tracking is enabled (or if I exit the app and go back in). I am using Native distortion and am not changing it programmatically.

I have ran the demo scene on iOS and have not been able to reproduce the same behavior.

101chris commented 8 years ago

Same problem here. Did anyone figure out a solution? It works in the Unity Editor but the head rotation does not work on the device unless I somehow move away from the unity game (using the home screen or recent apps, etc), then it kicks in when I go back to the game. not setting any VRModeEnabled. I have my CardboardMain prefab contained in a GameObject that has an animation on it, if that makes any difference.

smdol commented 8 years ago

Is the common element from loading a new scene or starting with VR mode disabled? And so far, not recreatable with the demo scene?

Could anyone make a stripped down test case that shows the problem and share it here? I will definitely take a look.

Possible workaround: There is a function on the VRDevice class called OnPause(bool). Normally it is only called by Cardboard from OnApplicationPause(). The workaround is to edit the Cardboard script and call OnPause() twice, first with true, then with false, right after you switch VR mode on. Let me know if you try it and whether that has any effect, positive or negative.

101chris commented 8 years ago

Yes that worked! I made a public function in Cardboard.cs like this:

  public void DevicePause(bool pause) {
    if (device != null) device.OnPause(pause);
  }

and called GetComponentInChildren<Cardboard>().DevicePause(false) in a script's Start() method, and it now works. I didn't need to call it twice (first true then false) just false worked.

so I guess it's getting stuck in pause mode somehow. unfortunately I don't have a simple case to reproduce, as I'm injecting cardboard into already built scenes.

thanks!

mchowdhury commented 8 years ago

The solution above worked for me too! Thanks for the advice!

@smdol is this technically a bug in the SDK, or is this the correct way to load scenes going forward? Should we expect an updated SDK containing a fix for this?

smdol commented 8 years ago

It will definitely be fixed in an SDK update. In the meantime, this sounds like the workaround to use.

smdol commented 8 years ago

This bug ought to be fixed in the new v0.6 release of the SDK. There was a bug that was not updating the stereo cameras' TargetTexture property.

101chris commented 8 years ago

FYI, so far, with the new release, I have not used the DevicePause() workaround, and i have not had this issue crop up, so yes it does appear to be fixed!

nathanmartz commented 8 years ago

Great. Considering this resolved.

nathanmartz commented 8 years ago

Derp.

ddcb commented 8 years ago

I am having the same problem with the latest cardboard sdk v0.6

Every time I run my app the camera wont respond to any Iphone movement, the app is not frozen as I can still interact with the screen but the camera is stuck. However, the camera can be unstuck if I tap the settings gear icon in the bottom center of the screen and then tap the back button or if I press the home button and reopen the app without re launching. Any ideas?

This is the script I am using to enable the gyroscope.

     #if UNITY_EDITOR

     using UnityEngine; 
     using System.Collections;

     public class GyroscopeEnable : MonoBehaviour
     {    
        private Gyroscope gyro;

         void Start ()
         {
             if (SystemInfo.supportsGyroscope) {
                 gyro = Input.gyro;
                 gyro.enabled = true;
             }
         }
     }

     #endif

After that, I edited line 75 of UnityEditorDevice.cs and change the line to read:

 if (RemoteCommunicating) {
smdol commented 8 years ago

The symptom of not tracking the head can arise if you accidentally have more than one Cardboard component in the scene. They stomp on each other and you get no head tracking. Look for the error message "There must be only one Cardboard object in a scene." in the logs.

ddcb commented 8 years ago

I opened a new project and scene to try and fix the glitch. On my Hierarchy window there is only one CardboardHead. There are no extra cardboard objects but if I press play a second Cardboard object appears on the Hierarchy Window. I stop the game and the object disappears

smdol commented 8 years ago

Which version of the SDK is it? We stopped auto-generating the Cardboard component in v0.6.

Also, the CardboardHead prefab doesn't contain a Cardboard.cs script. That script lives on the CardboardMain prefab, or in the latest SDK also on the CardboardManager prefab.

ddcb commented 8 years ago

I was using a version downloaded on jan 8, 2016. After not being able to fix the glitch I downloaded the newest sdk on Mar 1, 16 (two days ago). I am running only the new sdk on the project I just created

ddcb commented 8 years ago

I just deleted cardboardhead prefab and placed cardboardmain instead. The auto generated cardboard component no longer appears and disappears everytime I test play but I am still having the same issue with the camera being stuck on the first time I play the app.

smdol commented 8 years ago

Oh right, my mistake. There is one spot in the code that will still autogenerate a Cardboard.cs component, and that is in StereoController, which is in the CardboardHead prefab. So that's expected. The issue on the phone, not head tracking, is something else. Any errors in your Xcode console?

ddcb commented 8 years ago

xcode points out some issues but no errors

issues

smdol commented 8 years ago

Hmm. Ok, this is interesting. I guess the first thing to do is clear the decks and start with a sanity check. Try following the procedure here: https://developers.google.com/cardboard/unity/get-started-ios Do this on a fresh new project. And if you still get no head tracking out of that, could you zip the whole Unity project and share it? We have locally done this test and don't see this problem, so the problem is to figure out what is different in your setup vs ours.

ddcb commented 8 years ago

Ok, I have already opened a new project. Added the sdk along with the demo. The demo works if I am using the mouse pad pressing alt or ctrl but no head tracking on my phone via unity remote. Should I add the gyroscope enable script I was using earlier or should my iphone already be receiving headtracking by only setting my device on the editor project settings?

smdol commented 8 years ago

Is this problem only happening in the Remote? That's not officially supported, but there's a variable in Cardboard.cs called UseUnityRemoteInput that needs to be set to true. It's a very poor VR experience, and I've never tried it on iOS. If you actually build and deploy the app to the phone, do you get head tracking?

ddcb commented 8 years ago

The demo headtracking is working on my phone!