Forum Discussion
motorsep
10 years agoMember
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.
I wonder how to print debug text in Gear VR ?
Thanks.
11 Replies
Replies have been turned off for this discussion
- cyberealityGrand ChampionYou 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/ - owenwpExpert ProtegeIf 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.
- motorsepMember
"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 ? - owenwpExpert ProtegeThe 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.
- guigouHonored GuestHere 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 :) - petereptProtegeI 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,
Peterusing 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);
}
} - motorsepMemberCool stuff Peter, thanks a bunch!
Btw, I sent you an e-mail. - guneyozsanHonored Guest
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<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 :)
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). - AnonymousYou can use a unity asset store plugin called Reporter to receive emails with logs and screenshots automatically on errors.
- motorsepMemberDamn, 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.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 5 months ago
- 3 months ago
- 4 years ago
- 2 years ago