Last active
February 11, 2025 18:51
-
-
Save bearlikelion/45f523a8670ec625d1334598f9632228 to your computer and use it in GitHub Desktop.
Godot debug screen console autoload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!")