I want to clear content of console window.
At present, I have to press clear button each time to rub content. Because by default console window clears when we play our project.
I want keyboard shortcut for this so that I can reduce my labour work.
I want to clear content of console window.
At present, I have to press clear button each time to rub content. Because by default console window clears when we play our project.
I want keyboard shortcut for this so that I can reduce my labour work.
frarees idea goes in the right direction, however “Debug.ClearDeveloperConsole” is related to the developer console which is built into a Unity build itself when you create a debug-build.
Like ever so often Unity made the LogEntries class, which contains the needed Clear method, an internal class, but thanks to reflection you can call it like this:
// C# editor script
using UnityEngine;
using UnityEditor;
static class UsefulShortcuts
{
[MenuItem ("Tools/Clear Console %#c")] // CMD + SHIFT + C
static void ClearConsole () {
// This simply does "LogEntries.Clear()" the long way:
var logEntries = System.Type.GetType("UnityEditorInternal.LogEntries,UnityEditor.dll");
var clearMethod = logEntries.GetMethod("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
clearMethod.Invoke(null,null);
}
}
In unity 2017.1 LogEntries are located in UnityEditor namespace, not in UnityEditorInternal. So you should use this code from now on:
using System.Reflection;
public static void ClearConsole()
{
var assembly = Assembly.GetAssembly(typeof(SceneView));
var type = assembly.GetType("UnityEditor.LogEntries");
var method = type.GetMethod("Clear");
method.Invoke(new object(), null);
}
This is the code that works using Unity 5. Remember to put using System.Reflection; and using UnityEditor; at the top:
public static void Misc_ClearLogConsole() {
Assembly assembly = Assembly.GetAssembly (typeof(SceneView));
Type logEntries = assembly.GetType ("UnityEditorInternal.LogEntries");
MethodInfo clearConsoleMethod = logEntries.GetMethod ("Clear");
clearConsoleMethod.Invoke (new object (), null);
}
Check how MenuItem works to define custom shortcuts.
using UnityEngine;
using UnityEditor;
static class UsefulShortcuts {
[MenuItem ("Tools/Clear Console %#c")] // CMD + SHIFT + C
static void ClearConsole () {
Debug.ClearDeveloperConsole ();
}
}
Remember to place this script in an Editor
folder. More info here.