Search Unity

Building a stand alone exe with Google Cardboard

Discussion in 'AR/VR (XR) Discussion' started by shanebro, Nov 17, 2016.

  1. shanebro

    shanebro

    Joined:
    Nov 17, 2016
    Posts:
    2
    I have a Unity project that contains the Google VR SDK.
    When I press play, everything works as it should, as well as the Oculus Rift head set displaying the correct images.

    When I try to build and run, I get a series of errors. Mostly NullReferenceExceptions.

    Is it even possible to build an exe for Windows with the Google Cardboard SDK?


    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2.   at Cardboard.OnApplicationFocus (Boolean focus) [0x00000] in <filename unknown>:0
    3.  
    4. (Filename:  Line: -1)
    5.  
    6. NullReferenceException: Object reference not set to an instance of an object
    7.   at Cardboard.Projection (Eye eye, Distortion distortion) [0x00000] in <filename unknown>:0
    8.   at CardboardEye.UpdateStereoValues () [0x00000] in <filename unknown>:0
    9.   at CardboardEye.Start () [0x00000] in <filename unknown>:0
    10.  
    11. (Filename:  Line: -1)
    12.  
    13. NullReferenceException: Object reference not set to an instance of an object
    14.   at Cardboard.Recenter () [0x00000] in <filename unknown>:0
    15.   at Menu.recalb () [0x00000] in <filename unknown>:0
    16.   at Menu.Start () [0x00000] in <filename unknown>:0
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    Cardboard is only usable in Android or iOS, neither of which support making exe's. It may compile as C# but it won't run since there are no x86 Windows compatible libraries that I am aware of.
     
    wccrawford likes this.
  3. demonixis

    demonixis

    Joined:
    Aug 20, 2013
    Posts:
    185
    You have to hack a bit the source code to enable the editor emulation in the final build. I did it for a project.
     
  4. shanebro

    shanebro

    Joined:
    Nov 17, 2016
    Posts:
    2
    Any hints where to find a guide for this? I've tried googling but can't find much.
     
  5. demonixis

    demonixis

    Joined:
    Aug 20, 2013
    Posts:
    185
    Open the sources and replace some #if UNITY_EDITOR by #if UNITY_EDITOR || UNITY_STANDALONE

    BaseVRDevice.cs
    Code (CSharp):
    1. #if UNITY_EDITOR || UNITY_STANDALONE
    2. device = new EditorDevice();
    3. #elif ANDROID_DEVICE
    4. // Rest of the code
    5. #endif
    EditorDevice.cs
    Code (CSharp):
    1.  
    2. #if UNITY_EDITOR || UNITY_STANDALONE
    3. using UnityEngine;
    4.  
    5. private bool RemoteCommunicating {
    6.     get {
    7.         if (!remoteCommunicating) {
    8.             remoteCommunicating = EditorApplication.isRemoteConnected;
    9.             // You have to comment that line
    10.             //remoteCommunicating = EditorApplication.isRemoteConnected;
    11.         }
    12.         return remoteCommunicating;
    13. }
    14. // Rest of the code
    15. #endif
    16.  
    GvrViewer.cs
    Code (CSharp):
    1.  
    2. #if UNITY_EDITOR || UNITY_STANDALONE
    3. /// Restores level head tilt in when playing in the Unity Editor after you
    4. /// release the Ctrl key.
    5. public bool autoUntiltHead = true;
    6. // The rest of the code
    7. #endif
    8.  
     
    Gazzx likes this.
  6. carlosfarinhas

    carlosfarinhas

    Joined:
    Apr 12, 2016
    Posts:
    10
    demonixis thank you! Excelent hacking. That work around worked for me.
     
  7. Hykato

    Hykato

    Joined:
    Dec 29, 2016
    Posts:
    3
    When I replace these 3 #if UNITY_EDITOR by #if UNITY_EDITOR || UNITY_STANDALONE, if i try to build i have an error.

    Assets/GoogleVR/Legacy/Scripts/Internal/VRDevices/EditorDevice.cs(17,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing an assembly reference?
     
  8. Hykato

    Hykato

    Joined:
    Dec 29, 2016
    Posts:
    3



    When I replace these 3 #if UNITY_EDITOR by #if UNITY_EDITOR || UNITY_STANDALONE, if i try to build i have an error.

    Assets/GoogleVR/Legacy/Scripts/Internal/VRDevices/EditorDevice.cs(17,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing an assembly reference?
     
  9. relf218

    relf218

    Joined:
    Dec 21, 2016
    Posts:
    1
    Hi, I managed to fix it by using the following
    Code (CSharp):
    1. #if UNITY_EDITOR|| UNITY_STANDALONE
    2.  
    3. using UnityEngine;
    4. #if UNITY_EDITOR
    5. using UnityEditor;
    6. #endif
    7. using System.Collections.Generic;
    Code (CSharp):
    1. private bool RemoteCommunicating {
    2.       get {
    3. #if UNITY_EDITOR
    4.         if (!remoteCommunicating) {
    5.           remoteCommunicating = EditorApplication.isRemoteConnected;
    6.         }
    7.         return remoteCommunicating;
    8. #endif
    9. #if UNITY_STANDALONE
    10.         return false;
    11. #endif
    12.         }
    13.     }
     
    Gazzx likes this.
  10. imran4125

    imran4125

    Joined:
    Jul 12, 2017
    Posts:
    17
    Hi,
    Is there any way to achieve this for the latest googlevr sdk ? As after adding the latest googlevr sdk and making PC build it says add a platform Daydream or Cardboard... but there is no such option in PC build under virtual reality supported player setting...Any help ? The old hacks told above worked great before.
     
  11. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    Cardboard and Daydream are iOS and Android ONLY. You can not build a standalone EXE using those devices. The only thing you can do is add a PC compatible device to the PC VR Device list and run with that.