Showing the alert icon in the editor's scene tree

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Blaise Bernier

I’m building a plugin and I want one of my custom nodes to show the warning sign when some of the properties are not set properly.

Is there any way to do that?

:bust_in_silhouette: Reply From: volzhs

There is a virtual method Node::get_configuration_warning in cpp.
but it’s not exposed to gdscript.

I’m not sure if there is any workaround for it.
you can open issue and discuss about this on github.

I opened the issue!

Blaise Bernier | 2018-05-03 00:55

:bust_in_silhouette: Reply From: Dlean Jeans

As of 3.1 you can do this by adding _get_configuration_warning to your GDScript:

tool # must be a tool script to work
extends Node

export(String) var name:String

func _get_configuration_warning():
	if not name:
		return 'Name not set'
	return ''
2 Likes

For anyone finding this as of today, things changed slightly.
Use _get_configuration_warnings to return an PackedStringArray of additional warnings (besides the one the Node you extended already returns)

func _get_configuration_warnings() -> PackedStringArray:
    var warnings: PackedStringArray
    if not is_okay:
        warnings.append("is not okay")
    return warnings

The script still has to be in @tool mode.
When variables like is_okay are changed, call update_configuration_warnings() to update them. They are also updated when you move the node in the scene tree or enter the scene again, but that’s obviously unreliably and annoying.

Link to docs: Node — Godot Engine (stable) documentation in English