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
14
Question by siddharth3322 · May 14, 2014 at 09:46 AM · keyboardconsoleunity4.3shortcuts

Clear Console Window

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.

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
28
Best Answer

Answer by Bunny83 · May 14, 2014 at 11:42 AM

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);
     }
 
 }
Comment
Add comment · Show 6 · 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 siddharth3322 · May 14, 2014 at 11:49 AM 0
Share

Absolutely right.

avatar image huulong · Sep 10, 2015 at 04:35 PM 0
Share

Thanks! Also note that if, like me, your console shortcut is already cmd+shift+C (I'm on Unity 5.2), choose another one for ClearConsole.

avatar image KirillKuzyk · Jul 29, 2017 at 09:50 PM 6
Share

In unity 2017.1 LogEntries are located in UnityEditor namespace, not in UnityEditorInternal. So just replace UnityEditorInternal with UnityEditor to make this code work for unity 2017.1.

avatar image molul · Apr 30, 2018 at 06:41 AM 0
Share

Hi! Thanks for the script. However, I'm not sure how to use it. Should I add this to, say, the $$anonymous$$ain Camera object for the shortcut to be available?

Thanks in advance.

avatar image Bunny83 molul · Apr 30, 2018 at 03:02 PM 1
Share

This script is not a $$anonymous$$onoBehaviour and therefore not a component. So it can't be "attached" to anything. It's an editor script which you just have to put in a subfolder called "editor" inside your assets folder. You don't have to do anything with that script. It's a static class and the "$$anonymous$$enuItem" attribute will add a new menu item to the Unity editor main menu. Specifically once you have that script in an editor folder you should have the "Clear Console" menu item inside the Tools menu.


$$anonymous$$eep in $$anonymous$$d that as you can read in the comment above since about Unity 2017 they moved the LogEntries class from the UnityEditorInternal namespace to the UnityEditor namespace. If you use an older version of Unity (at least up to Unity 5.6) you have to use my version. If you use Unity 2017 or newer you have to change "UnityEditorInternal" to "UnityEditor".

avatar image molul Bunny83 · Apr 30, 2018 at 03:26 PM 0
Share

I just noticed the "Remember to place this script in an Editor folder", sorry. It works now.

Thanks a lot!

avatar image
17

Answer by KirillKuzyk · Jul 29, 2017 at 09:47 PM

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);
 }
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 Phantom_101 · Jan 02, 2018 at 11:29 PM 0
Share

Thank you so much for posting this answer. I have been searching for the solution for a long time. :D

avatar image Vadol · Feb 07, 2019 at 09:26 AM 0
Share

What is "SceneView"?

avatar image kaliAJ · Aug 14, 2020 at 11:32 AM 0
Share

The function does its job. But don't know why I got logged out from the unity hub. And now I cannot sign in from the hub. it just shows the blank page but it never loads. This never happens to me but today, after using this code. also, the Unity Hub lost the editor's path. does anyone know why this happened? @KirillKuzyk @Yo318 @Vadol @astracat111

avatar image
2

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

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);
 }
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 DSivtsov · Jul 24, 2021 at 09:35 PM 0
Share

also Remember to put "using System"

avatar image
0

Answer by frarees · May 14, 2014 at 09:56 AM

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.

Comment
Add comment · Show 2 · 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 siddharth3322 · May 14, 2014 at 11:11 AM 1
Share

Using this I can't able to clear console. Though Tools menu created but it can't perform any action on click or key press.

So please give some guidance and thanks for reply.

avatar image voxellstudios · Feb 03, 2021 at 02:19 PM 0
Share

@siddharth3322 It only clear errors, not all logs will be cleared

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

34 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Load Scene When... 1 Answer

What is Wrong With This Section of my Script? 1 Answer

Show console on-screen keyboard on demand 0 Answers

Keyboard Input Problem 1 Answer

MonoDevelop "search document outline" shortcut 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