- Home /
Return console log as an array?
Is there any way to get the console as an array?
Say I were to do "print("this array number 0");" and then "print("this is 1");" and then have a GUI.Label that had the text as "theLogArray[1]".
Is this possible? I tried to search it on Google, but it's stupid and gives me completely off-topic answers.
This is the reason that I ask so many Unity questions on here. Google never works for me.
Answer by KuR5 · Jun 16, 2016 at 01:37 PM
Hey,
It is possible. Please find the example.
Thank you!
This worked exactly how I wanted it!
What exactly is "StackTrace"?
And for anyone who uses JS like me, here you go.
import System.Collections.Generic;
#pragma strict
static var log : List.<String> = new List.<String>();
function OnEnable(){
Application.RegisterLogCallback(HandleLog);
}
function OnDisable(){
Application.RegisterLogCallback(null);
}
function HandleLog(input : String, st : String, type : LogType){
if(type == LogType.Error){
log.Add("Error: "+input);
}
if(type == LogType.Log){
log.Add("Note: "+input);
}
if(type == LogType.Exception){
log.Add("Exception: "+input);
}
if(type == LogType.Assert){
log.Add("Unity Error: "+input);
}
}
As you can see, warnings are not my friends. I use legacy and Unity decides to spam me with warnings about that.
Your answer
Follow this Question
Related Questions
How do I change the default application used to open logs from the Unity editor? (on Mac) 1 Answer
command-line build: output to stdout instead of log ? 2 Answers
How do I write to the console? 5 Answers
How can I handle console logging, large amount of text over time 0 Answers
How do you open the Player Log? 2 Answers