Skip to content

Instantly share code, notes, and snippets.

@bearlikelion
Last active May 10, 2024 21:44
Show Gist options
  • Save bearlikelion/45f523a8670ec625d1334598f9632228 to your computer and use it in GitHub Desktop.
Save bearlikelion/45f523a8670ec625d1334598f9632228 to your computer and use it in GitHub Desktop.
Godot debug screen console autoload
extends Node
var debug: bool = OS.has_feature("debug")
@onready var panel: Panel = Panel.new()
@onready var canvas_layer: CanvasLayer = CanvasLayer.new()
@onready var rich_text_label: RichTextLabel = RichTextLabel.new()
# @onready var theme: Theme = load("res://SurvivalScape.theme") # Your custom theme file
func _ready() -> void:
process_mode = Node.PROCESS_MODE_ALWAYS
if debug:
if OS.get_name() == "Android" or OS.get_name() == "iOS":
pass
else:
canvas_layer.layer = 128
panel.size = Vector2(360, 120)
# panel.theme = theme
panel.set_anchors_preset(Control.PRESET_TOP_LEFT, true)
panel.self_modulate = Color(1, 1, 1, 0.69)
rich_text_label.text = ""
# rich_text_label.theme = theme
rich_text_label.set_anchors_preset(Control.PRESET_FULL_RECT)
rich_text_label.scroll_following = true
panel.add_child(rich_text_label)
canvas_layer.add_child(panel)
add_child(canvas_layer)
func _input(event: InputEvent) -> void:
if event.is_action_pressed("toggle_console"):
if panel.visible:
panel.visible = false
else:
panel.visible = true
func print(message: String) -> void:
if debug:
if rich_text_label:
rich_text_label.append_text(message + "\n")
print(message)
@bearlikelion
Copy link
Author

bearlikelion commented May 9, 2024

Create Log.gd and set it to your first Autoload in Project Settings as Log: Log.gd
Create a input action for "toggle_console" and bind it to a key

Code Usage:
Log.print("I am logging to both the log file and screen!")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment