Unity Google Cardboard display issue on iOS - c#

I've never encountered an issue like this before and everything I've tried to fix it has achieved nothing.
We have an app that uses Unity's built in Google Cardboard support that we have available on Android and iOS. The issue has never appeared on Android before, and also doesn't appear in a different project we have created using the same version of Unity (2018.1.1).
It appears the somehow when configuring the separate viewports for each eye it seems to get confused. The aspect ratio has been squished vertically and is stretching the displayed image. On top of this, the left and right eye appear to be facing in a cross eyed manor, where they should be facing more-or-less in the same direction. Here is an image representing the issue, with a line drawn around the current display area for each eye:
iOS cardboard display
This picture is of an iPhone 6, however this has been replicated on multiple devices including iPhone 8, iPhone X, and a few others that I cannot recall. Like I mentioned previously this has never happened on Android and also does not appear on iOS in a similarly setup project.
I have a suspicion that it has something to do with the way my Unity scenes are setup so I'll give a brief description of how things work at the moment.
Scene 1 - Menu scene
This is an entirely UI based scene (like most menus) and is setup in Portrait. It has a main camera that remains in standard mode (non-VR).
Scene 2 - Experience scene
This scene switches into Landscape view using code Screen.orientation = ScreenOrientation.Landscape. It has one camera in the scene that is initially in standard mode (non-VR) but can be toggled into VR using a button with this code:
public void SetStereoViewState(bool isActive) {
XRSettings.enabled = isActive;
#if !UNITY_EDITOR
// if device is a tablet (> 7" screen) always disable cardboard switch
// otherwise display only when cardboard mode is inactive
overlayCanvas.gameObject.SetActive(ScreenUtils.IsTabletDevice ? false : !isActive);
// needed to fix the aspect ratio when switching back to mono mode
vrCamera.ResetAspect();
#endif
Debug.Log("XRManager::SetStereoViewState | Enabling VR: " + isActive);
}
In a previous version of this app (running Unity 2017.2.0p2) this was never an issue, and is not an issue in a separate project also created in 2018.1.1.
What I've Tried So Far
camera.ResetAspect() - This was here to fix aspect issues when switching for VR to non-VR. I have enabled and disabled this when switching for every which way VR -> non-VR, non-VR -> VR etc. I have also delayed this until the next frame but without any change to the results
Enabling 'Cardboard' mode in the Landscape scene - The way I have always set my scene up in the past is to XRSettings.LoadDeviceByName({device_name}) at launch, in this case XRSettings.LoadDeviceByName("cardboard") but not enabling it with XRDevice.enabled = true until it is actually needed. | VR XRDevice.enabled = true - Non-VR XRDevice.enabled = false
Camera Setup
I don't think it's relevant since VR works perfectly fine on Android, but here is my somewhat default camera is setup:
Unity camera setup
I have considered setting up multiple cameras (left and right eye) but I can't see how this would make a difference as the aspect ratio is one of the issues.
If anyone has experienced a similar issue and has a fix, or has any advice in how to approach the situation in a different way that would be awesome.
NOTE:
Currently we are using Unity 2018.1.1 but I have also tried up to the most recent (at the time) 2018.1.5. A downgrade to 2017.x.x is not really possibly due to HttpWebRequests and Apple's somewhat frustrating IPv6 requirements which are broken until Unity 2018.x.x

FIXED
The issue is when loading 'cardboard' mode while in Portrait. Here is the code that I run at app launch to solve the issue:
private IEnumerator SetupCardboard() {
Screen.orientation = ScreenOrientation.Landscape;
XRSettings.LoadDeviceByName("cardboard");
yield return null;
Screen.orientation = ScreenOrientation.Portrait;
}

Related

Unity 3D freezing after leaving Game Mode (MRTK)

I've been working in a project some weeks now in a Mixed Reality project using Unity and MRTK and I've found a strange behaviour when adding screen capture to the application. I'm using Unity 2019.4.26f1, and I haven't found any issues so far but after adding this line of code
ScreenCapture.CaptureScreenshot("test.png");
into a script, I've realised that when I press Play and go into Game mode, everything goes correctly (the game starts, the screenshot is taken). BUT when I stop it and try to go into Play mode again, Unity freezes. If I don't press Play again, Unity still works until it tries to compile scripts or some heavy task like that, when it freezes and can only be closed with the task manager.
If I remove that line, Unity goes back to normal.
This issue cannot be reproduced in Unity 2020.3 LTS. Does this happen when the remoting play or in Editor? According to Choosing a Unity version and XR plugin - Mixed Reality | Microsoft Docs, if you target to HoloLens 2, please upgrade to the recommended 2020.3 LTS version that is stated in the document.
In addition, ScreenCapture is a Unity built-in class and if there are any usage questions, you may find support from Unity forum.

Why is the LineRenderer displaying on lowest layer on Android but not in Editor?

I have a 2D app with many canvases that have UI components. The canvases are displayed using SortingOrder for various functionality. At some point, I enable the signature canvas with a linerenderer.
On Android, the linerenderer always renders on the bottom layer so I cannot see the signature.
Yet, on the Editor, it works properly and displays on top where I can see the signature.
I have been playing around with layers, sorting orders but cannot make it work on Android on the top layer.
BTW: I'm pretty sure its not a shader problem (Line renderer is not working for android build game) because when I disable all canvases but the signature one and publish to Android it works fine.
---!!!! So I tested my App on Android Version 7.1.1 and it works as expected. It does the problem above on Android Version 9.
Any ideas??
I think if I upgrade the Unity version to the latest it will solve the problem. I am using Unity 2019.1 - I attempt to upgrade App to 2020.

Unity editor frame drops on Mac

I'm trying to use Unity in a Mac but the editor drops frames all the time. It shows it's rendering 330 fps but still feels laggy and dropping frames, also enemy movement is weird (I think it´s because it's dropping frames). This doesn't happen on windows (I tried both platforms). Before I used metal, and it rendered 35 - 45 fps dropping frames too. When I switched to OpenGL it went up to 330fps. I think the problem is not performance, but incompatibility of some kind. When I play the game built for Mac it works well.
Any idea of what could it be?
Statistics using OpenGL:
Statistics using Metal:
Make sure metal is enabled in the editor (not just when you export the game).
https://docs.unity3d.com/Manual/Metal.html
in old unity version metal was not enabled by default on mac and you had to use -force-gfx-metal and start the editor with terminal command line.
If it still not working I'm not sure what you can try... maybe try also to change your screen res.
Remember that Unity editor always use more resource, if the game is working fine when you export the game you can ignore the problem.

Custom Startup Window unity3d For Stand alone windows

I am trying to make a custom Startup window Or Before start Window for unity3d Standalone.
I do not know how to start Working on It i have Researched but got noting that can point me on the direction or a Kick start.
Is it even Possible to Do it As i have seen option in Player Settings--> Display Resolution Dialog-->Hidden By default But how dose it work and how i can set up my own window
If you have the Personal edition, you can't do a true customized start screen, as per their licenses page: https://unity3d.com/get-unity. You also cannot turn off the default Unity startup screen without using the Professional edition.
The Player Settings -> Display Resolution Dialog -> Hidden by Default options is to enable/disable a screen allowing the player to set the resolution before game start. Allowing the player to do this can have some undesired effects, depending on how you've set up your game's resolution. On this resolution screen, you can set a splash image by scrolling down the Player Settings inspector a bit.
To make a pseudo-startup screen that occurs after the actual Unity startup is not actually difficult. Take the image you want for your startup window, put it on a quad. Set your camera so that the quad fills the whole camera space. Add some light and you're done. You can add effects or animation as well. There are a number of other ways but this is probably the easiest.
Edit: I only have the Personal edition myself so I can't confirm any of the stuff in the following link works firsthand, but I expect you will find it and/or the links it contains to be very helpful in your efforts (the links referenced in it give quite a few worthwhile looking suggestions to accomplish it that I am unable to test):
https://gamedev.stackexchange.com/questions/72087/can-i-legally-remove-the-default-unity-splash-screen-by-removing-it-from-the-apk

Does Google Cardboard SDK work with Unity 5?

I have converted my working project from Unity into Unity 5 and now the stereoscopic display doesnt work.
It seems like the stereoscopic effect doesnt work. The display is split in the middle, and the shader is applied, but it seems like there is only once camera. Like there are no eye cameras.
The weirdest thing is that everything works perfectly in the editor, but when I run it on device it seems like the cameras are disabled.
I went through and tried everything in the "known issues" in Cardboard SDK Release Notes, but nothing works.
Has anyone succesfully run a Cardboard game on Unity 5?
Yes, I have done. Mine isn't big one but has major things that can be said to be using UNITY features as well. I cant predict your problem as such but Answer to this post is certainly YES.
I don't think that anyone has posted this yet, but it appears that the SDK is currently broken in Unity 5.
From: Cardboard SDK Release Notes
Unity 5 rendering issues: As of Unity build 5.0.0f4, the following steps should be taken to fix or ameliorate any rendering issues, such as an all-black screen, flashing textures, or non-stereo views:
Enable the Development Build option in the Build dialog. This seems to fix various rendering glitches, like flashing textures.
The root cause of the rendering glitches is under analysis, with assistance from Unity.
I have also found that the app has rendering issues when it initially runs when you hit "Build and Run". Closing the app from the task switcher and restarting seems to resolve the issue.

Categories

Resources