How do i clear the console?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MaximoTG98

I’m printing lots of lines in the console for my tests, but i need to clear the console when the game is running, Something like when i press X the console wipes every text i printed.

:bust_in_silhouette: Reply From: System_Error

You mean the Console thing that the Debugger is attached to? There’s a “CLEAR” button on the top right of that box, if the Output tab is selected.

But can i clear that output using code? I need to be able to clear the output tab from the game.

MaximoTG98 | 2019-02-02 14:26


did you ever figure out a way to clear the console from a script ?


troynall | 2020-05-24 02:25

:bust_in_silhouette: Reply From: Calinou

You can print an ANSI escape code that will clear the console this way:

func _ready():
    print("This message won't be visible.")
    print("The console was cleared.")

func clear_console():
    var escape = PoolByteArray([0x1b]).get_string_from_ascii()
    print(escape + "[2J")

Keep in mind this won’t work in the editor’s Output tab, as it doesn’t interpret ANSI escape codes. See this Stack Overflow question for more information on clearing/resetting a console using ANSI escape codes.