-
Notifications
You must be signed in to change notification settings - Fork 6
How to Use the Debug Menu
Samy CHAABI edited this page Feb 8, 2025
·
1 revision
The Debug Menu is a super handy tool to display values while the game is running, making debugging easier! 🚀
To access the Debug Menu instance, use the function from res://addons/godot-xr-tools/objects/viewport_2d_in_3d.gd:
## Get the 2D scene instance
func get_scene_instance() -> Node:
return scene_nodeThen, in the script where you want to use the Debug Menu (e.g., the player's script), declare:
@onready var debugMenu = $LeftHand/debug_menu
# Retrieve the instantiated debug menu UI scene
@onready var debugMenu_scene = debugMenu.get_scene_instance()📝 Note: The scene tree looks like this:

The script for the Debug Menu is simple and allows you to display any data dynamically:
extends Node2D
var content = ['firstThing', 'secondThing', 'thirdThing']
@onready var label = $Control/ColorRect/DebugMarginContainer/DebugVBoxContainer/content
@export var process_while_paused: bool = true
func _ready():
set_process(true)
set_process_unhandled_input(true)
set_process_input(true)
set_process_internal(true)
func update_content(newContent):
content = newContent
refresh_display()
func refresh_display():
label.text = "Debug Info 📊\n"
for item in content:
label.text += str(item) + "\n"
func get_content():
return content
func _process(delta: float) -> void:
refresh_display()To display values in the Debug Menu, just call update_content() like this:
# Example usage: updating debug info
var counter = 0
var btn_pressed
var incr = 0
func _process(delta: float) -> void:
counter += 1
debugMenu_scene.update_content(["Frame Count:", counter, "Button Pressed:", btn_pressed, "Increment:", incr])💡 Tip: Want to toggle the Debug Menu on/off with a button? Use this:
func _on_left_hand_button_pressed(name):
if name == "ax_button":
debugMenu.visible = !debugMenu.visibleThis lets you hide/show the Debug Menu during gameplay! 🎭
Now you’re all set to debug like a pro! 🏆 Happy coding! 💻🔥