Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by LukaKotar · Nov 19, 2013 at 12:29 AM · errorbuildconsoleclear

Clear console through code? (In development build)

Hi.

I have been playing around with the audio settings in the Unity editor, and I found out something weird - if I set the 'Default Speaker Mode' to 'Prologic DTS', it makes it makes it sound like an actual surround sound, on my stereo headphones. At the beginning of the game, an error will appear, telling me that the speaker mode is not supported, yet, it makes it sound so much better.

Question: How can I clear the console automatically, rather than having the player click "Clear" in the little console window that shows up on the lower left?

Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by ArkaneX · Nov 19, 2013 at 01:46 AM

You need to use Debug.ClearDeveloperConsole() But simply calling this method at Awake/Start will not work correctly. I did some tests, and it seems that developer console can't be cleared the same frame it became visible.

You can achieve what you want by using below sample (C#, but if you need it in JS, then you should be able to convert it fairly easily):

 void Start ()
 {
     StartCoroutine(ClearConsole());
 }

 IEnumerator ClearConsole()
 {
     // wait until console visible
     while(!Debug.developerConsoleVisible)
     {
         yield return null;
     }
     yield return null; // this is required to wait for an additional frame, without this clearing doesn't work (at least for me)
     Debug.ClearDeveloperConsole();
 }

Please be careful though, because this will clear any additional errors that might occur at the beginning of your game.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image LukaKotar · Nov 19, 2013 at 01:55 AM 0
Share

Thanks, that did the trick! I created an empty scene with a script that calls the function every frame, and loads the next level after the console is not visible, so there is no need to be concerned about missing any errors.

Edit: +1 for detailed answer

avatar image Jean-Fabre · Dec 05, 2014 at 01:15 PM 1
Share

That's odd, it doesn't work for me, the only solution that works is : http://answers.unity3d.com/questions/707636/clear-console-window.html

avatar image Ziplock9000 · Dec 10, 2020 at 08:28 AM 0
Share

Does not work 2020

avatar image
7

Answer by netlander · Apr 29, 2015 at 01:44 PM

For recent versions of Unity (4.x) try this:

         public static void ClearLog()
         {
             var assembly = Assembly.GetAssembly(typeof(UnityEditor.ActiveEditorTracker));
             var type = assembly.GetType("UnityEditorInternal.LogEntries");
             var method = type.GetMethod("Clear");
             method.Invoke(new object(), null);
         }
 


Don't forget to add:

 using System.Reflection;
 using UnityEditor;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
7

Answer by Mr_Mow · Oct 23, 2018 at 01:52 AM

According to EditorSourceCode on Github, you should now use:

 using UnityEditor;
 using System.Reflection;
 using System;
 
 public static class Utils {
     static MethodInfo _clearConsoleMethod;
     static MethodInfo clearConsoleMethod {
         get {
             if (_clearConsoleMethod == null) {
                 Assembly assembly = Assembly.GetAssembly (typeof(SceneView));
                 Type logEntries = assembly.GetType ("UnityEditor.LogEntries");
                 _clearConsoleMethod = logEntries.GetMethod ("Clear");
             }
             return _clearConsoleMethod;
         }
     }
 
     public static void ClearLogConsole() {
         clearConsoleMethod.Invoke (new object (), null);
     }
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image neoRiley · Nov 22, 2019 at 08:34 PM 0
Share

In unity 2019.2.9f1 this solution worked well

avatar image asimov99 · Jan 23 at 02:09 PM 0
Share

good for unity 2022.1 !

in editor mode too :)

avatar image astracat111 · Jan 23 at 02:29 PM 0
Share

Do not use new object(), it can create a memory leak. You can use the GameObject class though I believe, but you'll have to check this:

 GameObject invoker = new GameObject();
 invoker.name = "Invoke Clear Console";
 clearConsoleMethod.Invoke(invoker,null);
 GameObject.DestroyImmediate(invoker,false); //destroyimmediate because it's in editor

I had to do this for enumerators recently, I didn't know that new object() creates a memory leak in C#, so with the Editor Coroutines package I passed in a game object instead that just re-creates itself at all times in the editor.

avatar image
2

Answer by astracat111 · Feb 25, 2017 at 08:18 AM

This works differently now in Unity 5.5. They changed it to "UnityEditorInternal.LogEntries". Here's the code that will work using reflection for 5.5+. They'll probably change it again in 6 or something so consider yourself warned lol:

 using UnityEditor;
 using System.Reflection;

 public static void ClearLogConsole() {
     Assembly assembly = Assembly.GetAssembly (typeof(SceneView));
     Type logEntries = assembly.GetType ("UnityEditorInternal.LogEntries");
     MethodInfo clearConsoleMethod = logEntries.GetMethod ("Clear");
     clearConsoleMethod.Invoke (new object (), null);
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shieldgenerator7 · May 26, 2021 at 04:07 AM 0
Share

Change it to "UnityEditor.LogEntries" and it works for me in 2021.1.7f1

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

1 exception was raised by workers: See the Console for details. 0 Answers

Distribute terrain in zones 3 Answers

UnauthorizedAccessException | I Need Help Here. 1 Answer

can't build android app with facebook sdk 5 Answers

Development Build hangs, Normal Does Not 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges