Skip to content

How to Use the Debug Menu

Samy CHAABI edited this page Feb 8, 2025 · 1 revision

🛠️ How to Use the Debug Menu

The Debug Menu is a super handy tool to display values while the game is running, making debugging easier! 🚀

📌 Table of Contents


🔍 How It Works

📥 Retrieving the Debug Menu Instance

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_node

Then, 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:

cc589faf-f4d3-4a73-8371-712c585b250e


🎛️ Debug Menu Script

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()

🎮 How to Use

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.visible

This lets you hide/show the Debug Menu during gameplay! 🎭


Now you’re all set to debug like a pro! 🏆 Happy coding! 💻🔥

Clone this wiki locally