Trouble clearing console log....2017.1.0b4

Here fix this…

using System.Reflection;
using UnityEditor;

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);
}

and this…

    public static void F_ClearLog()
    {
        //Debug.ClearDeveloperConsole();
        //Assembly SampleAssembly = Assembly.GetAssembly(typeof(UnityEditorInternal.Macros));
        Assembly SampleAssembly = Assembly.GetAssembly(typeof(UnityEditorInternal.ComponentUtility));
        if (SampleAssembly == null)
        {
            Debug.LogError("!!! (SampleAssembly == null)");
        }
        else
        {
            Type type = SampleAssembly.GetType("UnityEditorInternal.LogEntries");
            if (type == null)
            {
                Debug.LogError("!!! (type == null)");
            }
            else
            {
                MethodInfo method = type.GetMethod("Clear");
                if (method == null)
                {
                    Debug.LogError("!!! (method == null)");
                }
                else
                {
                    method.Invoke(new object(), null);
                }
            }
        }
    }

and this…

using System;
using System.Reflection;


public static class DebugConsole
{


    public static void Clear()
    {
        Type.GetType("UnityEditorInternal.LogEntries,UnityEditor.dll")
            .GetMethod("Clear", BindingFlags.Static | BindingFlags.Public)
            .Invoke(null,null);
    }
}
1 Like

Hi particlemars,
It would be helpful if you could write whole sentences, and explain what you’re trying to do and what exactly goes wrong.

1 Like

Scripting Runtime Version Stable (.NET 3.5 Equivalent)
Scripting Beckend . Mono
Api Compatibility Level* . NET 2.0

I want to clear the debug console. I’m unable to read trajectory distance on debug console. It was scrolling down too fast. I’m unable slow down or set console debug speed slower. So, I copied clear the screen debug code online.

I’m getting red – “Type”. I.E.
Type.GetType(“UnityEditorInternal.LogEntries,UnityEditor.dll”)
Type logEntries = assembly.GetType (“UnityEditorInternal.LogEntries”);

Did this use to work in an earlier release?

Ehm, your first sample works in both 5.5 and 2017.1. What issue are you getting exactly? Also, “here, fix this” then posting code is rather impolite.

Edit: Oh, I see, “red Type”, ie. you do not have using System in your source file. Either do that or just replace the whole thing with:

typeof(Editor).Assembly.GetType("UnityEditorInternal.LogEntries").GetMethod("Clear", BindingFlags.Static | BindingFlags.Public).Invoke(null, null);
2 Likes