Skip to main content
Inspiring
November 13, 2015

How to print debug text in Gear VR ?

All tutorials/examples online for Unity C# code are made for conventional screens. So am sure there will be an issue using standard debug print functionality.

I wonder how to print debug text in Gear VR ?

Thanks.
    This topic has been closed for replies.

    11 replies

    Inspiring
    November 13, 2015
    You should be able to still use Log statements, I believe (at least it appears that way after a quick search).

    See this thread I found: http://forum.unity3d.com/threads/is-it- ... le.339572/
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Up and Coming
    November 13, 2015
    If you mean on screen, you will need to make your own UI that displays log text. Unity has a log callback function you can use to get logged messages.
    motorsepAuthor
    Inspiring
    November 14, 2015
    "owenwp" wrote:
    If you mean on screen, you will need to make your own UI that displays log text. Unity has a log callback function you can use to get logged messages.


    That would be lovely. I miss that kind of direct feedback from Quakes and Doom 3 :)

    Is it a trivial task to accomplish? Any idea if some ready to be used code (or at least tutorial) available somewhere ?
    Up and Coming
    November 14, 2015
    The new Unity UI system has the ability to place canvases in world space, and there are a bunch of video tutorials on their site. The simplest approach would be to just make a big text label and give it a formatted string. You should be able to piece it together from the samples in the docs.
    New Participant
    November 15, 2015
    Here is what I'm using:


    using UnityEngine;
    using System.Collections.Generic;
    using System.Linq;
    using UnityEngine.UI;

    static class OVRDebug {
    private static List<string> logs = new List<string> ();
    private static Text text;
    public static int nLogs = 10; // max number of lines to display. Can be changed


    static OVRDebug() {
    // will only be called once
    OVRCameraRig oVRCamera = GameObject.FindObjectOfType<OVRCameraRig> ();
    if (oVRCamera == null) {
    Debug.Log("Missing OVR camera");
    return;
    }
    // create a canvas and a text element to display the logs
    GameObject goCanvas = new GameObject ("Canvas");
    goCanvas.transform.parent = oVRCamera.gameObject.transform;
    goCanvas.transform.position = new Vector3(0, 4, -4); // arbitrary, works well for me

    Canvas canvas = goCanvas.AddComponent<Canvas> ();
    canvas.renderMode = RenderMode.WorldSpace;

    GameObject goText = new GameObject ("Text");
    goText.transform.parent = goCanvas.transform;
    goText.transform.position = Vector3.zero;
    text = goText.AddComponent<Text> ();
    text.font = Resources.GetBuiltinResource<Font> ("Arial.ttf");
    text.fontSize = 30;
    text.color = Color.black;
    RectTransform tr = goText.GetComponent<RectTransform> ();
    tr.localScale = new Vector3 (0.01f, 0.01f, 0.01f);
    tr.sizeDelta = new Vector2 (1000, 1000);
    }

    public static void Log(object log) {
    if (text == null) {
    // No OVR camera, fallback to normal logging
    Debug.Log(log);
    return;
    }
    // add the log to the queue
    string s = log.ToString ();
    logs.Add (s);
    // make sure we don't keep too many logs
    if (logs.Count > nLogs)
    logs.RemoveAt(0);
    PrintLogs ();
    }

    private static void PrintLogs () {
    string s = "";
    foreach (string k in logs) {
    s += k + "\n";
    }
    text.text = s;
    }
    }



    And then I can call OVRDebug.Log (...) from anywhere.
    It works well, excepted when there are objects in between :)
    Up and Coming
    November 17, 2015
    I wrote a script which broadcasts all Debug logs over the WiFi network.

    I use it all the time for tracing on GearVR. It's quicker and easier then messing about with ADB.

    To use it:

    1. Create a game object, and drag on the DebugLogBroadcaster.cs script

    2. Install a UDP server on your Windows, such as:
    SocketTest
    http://sourceforge.net/projects/sockettest
    Launch it, go to UDP tab, set port to 9999 and press Start Listening.

    3. IF you want to see stack traces, checkmark "Development Build" in build settings

    Now, when you run your app on GearVR and it's on the same network, you'll receive all debug logs.

    Good luck,

    Peter

    using UnityEngine;
    using System;
    using System.Text;
    using System.Net.Sockets;
    using System.Net;

    /*
    * Broadcast all Debug Log messages on the current WiFi network
    * By Peter Koch <peterept@gmail.com>
    *
    * Useful for debugging GearVR builds over WiFi
    *
    * Use this with any UDP Listener on your PC
    * eg: SocketTest
    * http://sourceforge.net/projects/sockettest/
    * Launch the app, go to UDP tab, set port to 9999 and press Start Listening
    *
    * Important Note:
    * - Callstacks are only sent in non-editor builds when "Development Build" is checkmarked in Build Settings
    */
    public class DebugLogBroadcaster : MonoBehaviour
    {
    public int broadcastPort = 9999;

    IPEndPoint remoteEndPoint;
    UdpClient client;

    void OnEnable()
    {
    remoteEndPoint = new IPEndPoint(IPAddress.Broadcast, broadcastPort);
    client = new UdpClient();
    Application.logMessageReceived += HandlelogMessageReceived;
    }

    void OnDisable()
    {
    Application.logMessageReceived -= HandlelogMessageReceived;
    client.Close();
    remoteEndPoint = null;
    }

    void HandlelogMessageReceived (string condition, string stackTrace, LogType type)
    {
    string s = stackTrace.Replace ("\n", "\n ");

    string msg = string.Format ("[{0}] {1}{2}",
    type.ToString ().ToUpper (),
    condition,
    "\n " + stackTrace.Replace ("\n", "\n "));
    byte[] data = Encoding.UTF8.GetBytes(msg);
    client.Send(data, data.Length, remoteEndPoint);
    }
    }
    Check out my Unity VR development blog: http://talesfromtherift.com @peterept
    motorsepAuthor
    Inspiring
    November 18, 2015
    Cool stuff Peter, thanks a bunch!

    Btw, I sent you an e-mail.
    New Participant
    June 2, 2016

    guigou said:

    Here is what I'm using:


    using UnityEngine;
    using System.Collections.Generic;
    using System.Linq;
    using UnityEngine.UI;

    static class OVRDebug {
    private static List&lt;string&gt; logs = new List&lt;string&gt; ();
    private static Text text;
    public static int nLogs = 10; // max number of lines to display. Can be changed


    static OVRDebug() {
    // will only be called once
    OVRCameraRig oVRCamera = GameObject.FindObjectOfType&lt;OVRCameraRig&gt; ();
    if (oVRCamera == null) {
    Debug.Log("Missing OVR camera");
    return;
    }
    // create a canvas and a text element to display the logs
    GameObject goCanvas = new GameObject ("Canvas");
    goCanvas.transform.parent = oVRCamera.gameObject.transform;
    goCanvas.transform.position = new Vector3(0, 4, -4); // arbitrary, works well for me

    Canvas canvas = goCanvas.AddComponent&lt;Canvas&gt; ();
    canvas.renderMode = RenderMode.WorldSpace;

    GameObject goText = new GameObject ("Text");
    goText.transform.parent = goCanvas.transform;
    goText.transform.position = Vector3.zero;
    text = goText.AddComponent&lt;Text&gt; ();
    text.font = Resources.GetBuiltinResource&lt;Font&gt; ("Arial.ttf");
    text.fontSize = 30;
    text.color = Color.black;
    RectTransform tr = goText.GetComponent&lt;RectTransform&gt; ();
    tr.localScale = new Vector3 (0.01f, 0.01f, 0.01f);
    tr.sizeDelta = new Vector2 (1000, 1000);
    }

    public static void Log(object log) {
    if (text == null) {
    // No OVR camera, fallback to normal logging
    Debug.Log(log);
    return;
    }
    // add the log to the queue
    string s = log.ToString ();
    logs.Add (s);
    // make sure we don't keep too many logs
    if (logs.Count &gt; nLogs)
    logs.RemoveAt(0);
    PrintLogs ();
    }

    private static void PrintLogs () {
    string s = "";
    foreach (string k in logs) {
    s += k + "\n";
    }
    text.text = s;
    }
    }




    And then I can call OVRDebug.Log (...) from anywhere.

    It works well, excepted when there are objects in between :)


    You can overcome "objects in between" by putting debug objects to another layer and assigning a camera that renders only that layer with a large depth (say 100).
    March 21, 2018
    You can use a unity asset store plugin called Reporter to receive emails with logs and screenshots automatically on errors.

    motorsepAuthor
    Inspiring
    March 21, 2018
    Damn, this is an old post :) I've been using UE4 for a long while now. Hopefully Unity users can find this wealth of info handy.