+3 votes

I have a node that I want to draw some text for in the editor.

tool
extends Node2D
...
func _draw():
    ...
    if (get_tree() != null) and get_tree().is_editor_hint():
        draw_string(..., get_pos(), some_text, Color(1, 1, 1))

For draw_string I want to use the default editor font; it wouldn't make sense to add a Font property to this node and this is only for drawing in the editor. How do I get the default font?

in Engine by (291 points)

1 Answer

+4 votes
Best answer
var label = Label.new()
var font = label.get_font("")
draw_string(font, get_pos(), some_text, Color(1, 1, 1))
label.free()
by (9,794 points)
selected by

Feels kind of hacky to have to create a label first but it does work.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.