Gvr-unity-sdk: After updating to 0.6, If an app starts in portrait, stereo view is cropped and tiny (iOS & Android)

Created on 18 Jan 2016  Â·  44Comments  Â·  Source: googlevr/gvr-unity-sdk

Unity 5.3.1p1
Mac OS 10.11.2

Reproduction steps:

  • Set default orientation to auto-rotate
  • Make a simple scene that only has CardboardMain and a few cubes (or whatever you want)

    • remove CardboardAudioListener from the Head gameobject because that can cause crashes (at least on ios)

  • Launch the app while holding the phone in portrait orientation
  • once launched, rotate to landscape

Also It doesn't matter if VRMode starts enabled or disabled, either way if you start in portrait the below happens.

Screenshots:
iOS:
2016-01-18 13 21 31

Android:
9b57115f4c467460fa50a9c33f83e4c7a4b4bb898bf4ce731epimgpsh_fullsize_distr

The above is just a demonstration of the issue, but I'm trying to do the same thing in my project. I'm starting in portrait in order to start on a "menu screen", and then later transition to a VR scene. However, I've also placed Cardboard in this starting scene to act as the camera (with VRMode, head tracking, etc. all disabled).

Most helpful comment

I'm not at the computer at the moment I'll send you my wrapper that handles
switching in and out of cardboard mode.

On Sun, 29 Jan 2017, 11:53 gtStation, notifications@github.com wrote:

@raldred https://github.com/raldred - that does not seem to help. Any
specific way you are doing this?

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/googlevr/gvr-unity-sdk/issues/144#issuecomment-275909065,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACQ6PoEMCnipJR9Nn6wiQ_RK2cyAAQAks5rXH23gaJpZM4HHJYM
.

All 44 comments

Yep, it's a current limitation of the SDK that it requires Landscape Left orientation to be in effect when Cardboard is instantiated and active (not just for the picture, but also for the gyro readings). You can change it in code by assigning to Screen.orientation, I believe.

Thanks, I'll whip up with a work-around then.

Hi! I'm having the same exact problem.

If the scene starts in portrait mode and I then switch to landscape left and then enable VR, this problem occurs.

this problem wasn't happening before with version 0.5.2 and I can't find the reason behind this.

I've scanned through the whole code for a hint on what could be going on and I've failed...

@smdol can you please check this?

The project I'm developing requires me to have the main UI in portrait mode, select a scene and start the VR experience. The experience occurs in the same scene by simply loading a texture to a reversed sphere and enabling the VR mode (previously switching to Landscape Left).

I tried putting this into separated scenes and the problem persists.

I also tried putting this in a thread that first switches to Landsacpe Left, waits 0.5 seconds, enables VR mode, disables distortion, waits 0.1secs enables distortion again. I also tried enabling VR mode once on Landscape Left, disbaling it after a brief time, then enabling it again... nothing... the problem persists.

Thanks in advance for any help you can bring to us!

@dill0wn I found a little workaround to the problem.

First, don't add any Cardboard script to your first scene (the one that starts in portrait mode).
Avoid calls to Cardboard.SDK before any actual call to go into VR mode. In my case, I'm saving any setting (for example the OnBackButton, DistortionMode, OnTrigger, DriftCorrection, etc...) on variables and as soon as you need to actually go into VR mode, then, what you have to do is to call a function that FIRST changes to LandscapeLeft, then, creates the Cardboard with Cardboard.Create() and then call a function to set everything from the variables if the Cardboard.SDK is null. Something like this:

public void GoVR(){
    Screen.orientation = ScreenOrientation.LandscapeLeft;
    if(Cardboard.SDK==null){
        Cardboard.Create ();
        AssignCardboardVariables();
    }
    Cardboard.SDK.VRModeEnabled = true;
    //Do whatever you need to do when you switch to VRmode.
}

void AssignCardboardVariables(){
    Cardboard.SDK.DistortionCorrection = _my_DistortionCorrectionMode;
    Cardboard.SDK.OnBackButton += BackDetected;
    if (FindObjectOfType<GazeInputModule>() == null) {
            InputSystem.AddComponent<GazeInputModule> ();
    }
    //etc...
}

Another Workaround I found (which I tried first and worked, but it is aesthetically ugly since it has to switch back and forth in the middle of the splash screen) is to add this line

    Screen.orientation = ScreenOrientation.LandscapeLeft;

Just before

    InitDevice();

On the Awake() function on the Cardboard.cs Script.

Hope it helps!

@dill0wn, does @nosmirck's workaround fix the issue?

@ybeaulieu, @nosmirck's workaround is the same thing I had in mind, but I have not yet tried it myself.

I can confirm that having a script changing the screen's orientation to LandscapeLeft _before_ Cardboard.Awake() is called does the trick. I'll have to do more extensive testing with scene loading, but so far it works!

I'm seeing the same issue, btw. Testing the above workarounds now...

those workarounds didn't work for me. What is the exact line where it needs to be landscape before firing into the cardboard sdk? @smdol

@brianchasalow So if you need to start the app in portrait mode, the Cardboard component has to not exist at that point in time. That means not adding the CardboardMain prefab or Cardboard scripts to the scene in the editor. It all has to be done in code, like @nosmirck wrote above. Basically, as @ybeaulieu said, make sure the screen is set to LandscapeLeft before Cardboard.Awake() is called. If you need to debug, add a Debug.Log to Cardboard.Awake(), as well as the point in code where you set the orientation, and see which is happening first in your logs.

@brianchasalow You might need to play around with the Script Execution Order. I had to place Cardboard after the default time, otherwise I had cases where Cardboard's Awake() was executed before the code that's supposed to set the screen orientation to LandscapeLeft. Having some Debug.Log and checking logcat with adb helped me find the issue and properly order my scripts.

so, it turns out it needs to wait a frame or so after setting Screen.orientation before I instantiate a prefab/ call into the Cardboard SDK. That's new to 0.6 ( I used to call it immediately after setting Screen.orientation)

@brianchasalow You are right! I started to experience the issue again, then I noticed that I needed at least a frame before calling create, so I changed my GoVR script to this:

public void GoVR(){
    StartCoroutine(GoVRThread());
}
IEnumerator GoVRThread(){
    Screen.orientation = ScreenOrientation.LandscapeLeft;
    if(Cardboard.SDK==null){
        yield return new WaitForSeconds (0.1f);
        Cardboard.Create ();
        AssignCardboardVariables();
    }
    Cardboard.SDK.VRModeEnabled = true;
    //Do whatever you need to do when you switch to VRmode.
}

You can change the WaitForSeconds for an EndOfFrame, however, I did it like that just to make sure it had enough time to switch the screen orientation.

Hello,

So I'm having the same bug with 0.6 and implementing @nosmirck 's code fixed it entirely in Android but only mostly on iOS. The new issue is that the cardboard border (mask?) is in the middle of the eye view now. Example screenshot: (Note: I changed the border's color to hot pink to make sure it wasn't an iOS clipping issue still.)

image1

Has anyone had this issue before or have any insight on the issue? (or even better solved it?)

Thanks!

Has there been any updates or work around yet? We are seeing the same issue as @VREvanS here for iOS here and need to release our app to the app store soon (urgent deadline), thanks!

For iOS, go into Player Settings and set the Default Orientation to Auto rather than Landscape Left. In Allowed Orientations, remove all entries except for Landscape Left. And continue to use @nosmirck's workaround above. Let me know if this helps or not.

Yeah, tried that didn't seem to work. We actually use the application in both Landscape and Portrait but we were starting it in Auto and with only LandscapeLeft checked. Issue still persists.

Well, The issues on iOS could not be fixed, none of my workarounds worked, so I ended up forcing all the app to landscape left mode only and I created the canvas in world space, I work it all in a resolution of 1000x1600, and I set up an ortho camera with size 500 that renders only this canvas with a culling mask and the clear flag is set to Depth only (Set the depth to 100 and on the cardboard preRender and postRender change their depths to -10, 10 instead of -100, 100) now, I added a script to the canvas that does the following on Start:

    void Start () {
        canv = GetComponent<RectTransform> ();
        float ratio = ((float)Screen.width) / ((float)Screen.height);
        Vector2 size = new Vector2 (1000, ratio*1000);
        canv.sizeDelta = size;
        canv.localRotation = Quaternion.Euler (new Vector3 (0, 0, 90));;
    }

Now, to switch between "portrait mode" and VR mode, I simply activate/deactivate the ortho camera while activating/deactivating the cardboard VR mode (this is because I need to have the background of the screen in non-vr mode with head tracking enabled)

So, the end result is an app that is always on LandscapeLeft from start but I manage myself to draw the UI in portrait mode whenever I need it.

However, I think that the Cardboard plugin should be able to handle this no matter the screen orientation. I know it is a hard thing to do, but could be much more easier for developers to have the freedom to work in portrait and/or landscape and switch back and forth without having any issue, this is really important if you aim to make some interfaces like in the native cardboard application, if you want to mimic the way the cardboard supported apps are listed (with a 360 "banner" that you can move around using the tracking) is something impossible to do with the current sdk, unless you force the app to be landscape left and rotate the canvas... which is not the most elegant solution.

The problem is, Cardboard instance is a singleton and is caching something behind the scenes. So, if you _ever_ startup incorrectly where the app is portrait while Cardboard instance is instantiated, your app will be bugged forever and you will need to force quit the app and reopen it. We ran into this recently and it actually got released to the app store in its bugged state with v0.6.

Y'all need to fix this.

To reiterate: if i:
1) Set screen orientation to portrait
2) enable cardboard,
3) app is bugged.
4) then disable VR/cardboard mode, force screen orientation to landscapeleft,
5) re-enable cardboard,
6) app is still bugged.

If I startup the first time in landscapeleft before instantiating the Cardboard instance, everything will forever be okay.

The workaround doesn't work for us. Is there an ETA to when an official bug fix for this issue will come yet?

The workaround work for me.

private IEnumerator GoVRThread() {
        Screen.orientation = ScreenOrientation.LandscapeLeft;
        yield return new WaitForSeconds (0.1f);

        this.gameObject.AddComponent<StereoController> ();
}

Tried the workaround. Works for Android. Still a no-go for iOS. (I did change the orientation stuff to match iOS' orientation.auto, etc. stuff, still didn't work)

Has anyone had luck with this? We are close to release and still having problems with the iOS version.

We need the portrait mode because we need to input some information in a search box, and writing in landscape is not an option here. Boss needs this to be on portrait. At least, how can we try to fix this by ourselves?

Is there an estimation for the release of the new version of the Cardboard SDK?

Sorry for being pushy.

we set the iOS app to landscape left in build settings, and in Awake() set
Screen.orientation = ScreenOrientation.Portrait;

Seems to work.

On Tue, Mar 15, 2016 at 3:19 PM, Luis Pulido [email protected]
wrote:

Has anyone had luck with this? We are close to release and still having
problems with the iOS version.

We need the portrait mode because we need to input some information in a
search box, and writing in landscape is not an option here. Boss needs this
to be on portrait. At least, how can we try to fix this by ourselves?

Is there an estimation for the release of the new version of the Cardboard
SDK?

Sorry for being pushy.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
https://github.com/googlesamples/cardboard-unity/issues/144#issuecomment-196982348

EDIT: Just posted after @Scott-Driscoll, I think his answer seems to be better/cleaner. Just make sure your app starts in Landscape before allowing Portrait orientation once Awake() is done.


Hi, i'm part of the team with @VREvanS and @captainkw , we solved our issue doing some quick crossplatform changes on iOS and Unity, here is how we ended up solving it, hopefully this can apply to at least one person with a similar situation if they have problems with iOS.

On Unity call this at the end of the Awake() function in Cardboard.cs (Don't worry about changing Cardboard.cs for future renditions, as hopefully this bug should be fixed by then!)

  void Awake() {
        if (sdk == null) {
              sdk = this;
        }
        [....]
        AddCardboardCamera();
        #if UNITY_IOS
        CardboardIsAwake();
        #endif
  }

Make sure to have an external function for this:

    #if UNITY_IOS
    [DllImport ("__Internal")]
    public static extern void CardboardIsAwake();
    #endif

The next steps are going to be a little vague as how people approach their delegations differently.

The key idea is to have your delegate start your ViewController in forced landscape until you get CardboardIsAwake() is called, which you can then switch your ViewController to its intended orientations while Cardboard will work as intended.

So what I did was having the override func startUnity(application: UIApplication!) call (Or the ObjC equivalent) start a ViewController specifically in landscapeRight. I made a UINavigationController with a blank white UIViewController accompanying this with neither the Navigation bar nor the Status bar visible. We'll call this our interim ViewController.

So while Cardboard correctly calculates the view sizes during this whole process, it will eventually call CardboardIsAwake() onto the bridger function, for which you switch the current/interim ViewController with the main ViewController you are using for your app.

The end result is having the Unity Splash screen start, followed by a white screen showing for at most half a second, then finally to your application. Cardboard will now properly work as intended.

@Scott-Driscoll @apollow Thanks for your answers, I'll try this!

However, I have to ask something.

As I have Unity Pro, I can simply disable all the splash screens and make one of my own in the same scene I have everything (so I don't have to start with a splash scene and then load a new scene) and destroy it after a fade, it looks good.

So, Can I just start in Auto with only Landscape left enabled, let the cardboard.cs finish its awake and, after half a second, switch to portrait?

I didn't quite understand the override func startYnity thing. I'm not too familiarized with iOS development. I work mostly on Android.

I'll try with Scott's solution, but to make sure the cardboard is instantiated during awake, I'll call the switch to portrait in Start().

@nosmirck
_So, Can I just start in Auto with only Landscape left enabled, let the cardboard.cs finish its awake and, after half a second, switch to portrait?_

Yes, I think that's the core idea :+1:

Have there been any updates on this since this thread went cold? I'm finding myself in the same situation and I'm wondering if I should implement one of these work arounds, or if GoogleVR works better with this stuff now.

I don't believe this has been addressed yet.

OK, so, sorry for being a dum-dum, but what is it that I instantiate from script now? What libraries do I have to use?

I'll attempt to use the latest namespaces here since they are rapidly changing but they are out of sync with my project.

Do I need a
using Gvr; or a using Google.*;?

or something? How do I call
GvrViewerMain.Create() or Cardboard.Create() or whatever it is currently? What does my script need to find to call that, be it an existing component or a library?

Thanks

...any hope of Portrait support in GVR? Seems like a lost cause...

Can anyone here confirm if the v1 Cardboard release of today solves this longstanding issue?

Hi guys, is there any gist or project example with the patch for ios available ? I have the same problem too ^^

Also seeing this, and the suggested fixes don't seem to work.

If you are an Android user, go to GoogleVR>Scripts>Gvrviewer, find void Awake()

and add:

Screen.orientation = ScreenOrientation.LandscapeLeft;

worked for me!

You can also check this link:
https://forum.unity3d.com/threads/why-is-the-google-cardboard-view-getting-crushed-when-i-change-orientation.404265/

@zakezhang yeh that worked for me too, we're developing a tour app, parts of it are a traditional app so the app need to start up in portrait.

For iOS App, I fixed this issue by setting up correct deployment info & Device orientation to _Landscape Left_.
image

Is this not fixed yet?

The iOS solutions did not seem to help.

I found the only way around this ensure the scene started with GvrViewer
disabled and VRModeEnabled false.

When you want to drop into Cardboard force orientation to LandscapeLeft
before enabling GvrViewer.

On Sun, 29 Jan 2017, 09:52 gtStation, notifications@github.com wrote:

Is this not fixed yet?

The iOS solutions did not seem to help.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/googlevr/gvr-unity-sdk/issues/144#issuecomment-275903933,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACQ6NdaqYvpFYiNEszRpY-amYyblSkDks5rXGFQgaJpZM4HHJYM
.

@raldred - that does not seem to help. Any specific way you are doing this?

I'm not at the computer at the moment I'll send you my wrapper that handles
switching in and out of cardboard mode.

On Sun, 29 Jan 2017, 11:53 gtStation, notifications@github.com wrote:

@raldred https://github.com/raldred - that does not seem to help. Any
specific way you are doing this?

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/googlevr/gvr-unity-sdk/issues/144#issuecomment-275909065,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACQ6PoEMCnipJR9Nn6wiQ_RK2cyAAQAks5rXH23gaJpZM4HHJYM
.

@raldred hey buddy - happen to be able to post it?

There is a workaround solution for this. If you are using GVR in a separate scene, try setting the screen orientation to landscape before loading the scene. This way it works all the time.

What solved it for me was starting the app in landscape left then switching to portrait before showing our main menu. It seems like some initialization on startup required the app to be in landscape left.

Was this page helpful?
0 / 5 - 0 ratings