Edit outline color of a label via code

Godot Version

Godot 4.2.2

Question

Newbie here, I want to edit via code the outline color of label in Godot but it seems I can't find the exact property or method. I tried $Label.font_outline_color = Color.GREEN but it says "Invalid set index 'font_outline_color', although in the Godot doc it says that this property exists as a Theme Property. Is there something as a theme object?

image

1 Like

it’s here
add_theme_color_override("font_outline_color",Color.RED)

so you just need to:

$Label.add_theme_color_override("font_outline_color",Color.RED)

I want to change the outline of the label. It is red and I want it to be green.
image

Doesn’t work.
I added Label.add_theme_color_override("font_outline_color",Color.GREEN)

You need to add a size as well:
.add_theme_constant_override("outline_size", 3)

$PanelContainer/MarginContainer/Rows/GameOverLabel.text = "YOU WIN" $PanelContainer/MarginContainer/Rows/GameOverLabel.add_theme_color_override("font_outline_color",Color.GREEN) $PanelContainer/MarginContainer/Rows/GameOverLabel.add_theme_constant_override("outline_size", 5)
image
I still get Red

It is also clearly not 5 pixels wide.
Is it getting to this code?

The default text of the label is not “YOU WIN”, so it 100% gets viewed.

im pretty sure theres a property label_settings thats a LabelSettings resource and you can do this to it:

@onready var L : Label = $Label

func _ready() -> void:
	var setting : LabelSettings = LabelSettings.new()
	setting.outline_color = Color.RED
	setting.outline_size = 30
	#L.label_settings = setting

image

@onready var L : Label = $Label

func _ready() -> void:
	var setting : LabelSettings = LabelSettings.new()
	setting.outline_color = Color.RED
	setting.outline_size = 30
	L.label_settings = setting

image

idk why the image is looking like that but it works!

1 Like

Thank you so much. Why you declared that it is a LabelSettings when you already initialize it?

because I hadn’t assigned a settings value for it in the editor. It doesn’t come with a settings resource automatically, so you need to either initialise it in code like this, or make a resource here:
image
the settings for a label is a resource that gets saved to disk, so that you can reuse the same settings in any label you want, but the label itself is a node that gets saved to the scene, so it hadnt actually been initialised yet

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.