This AGMPluginAction does not inherit from the Node type. How can I specify a specific node?
Currently, it seems I can only specify it using @export var sprite_path: NodePath = NodePath().
A couple ways to try and go about it:
- NodePath
Type the path relative to the GameObject, like Sprite2D or UI/Label, then resolve it off p_owner at runtime (the snippet from before).
String name + find_child: this is the one I usually reach for. You type just the node name instead of a full path, which is more forgiving and survives the node getting moved around:
@export var text_node_name: String = ""
func on_state_enter(p_owner: Object) -> void:
var owner_node := p_owner as Node
if owner_node == null:
return
var label := owner_node.find_child(text_node_name, true, false) as RichTextLabel
if label != null:
label.text = "Hello"
- Clickable list
You can build your own dropdown instead of leaning on Godot’s picker. It’s a bit more involved, but you scan the open scene in _validate_property and feed the node names in as suggestions:
@export var text_node_name: String = ""
func _validate_property(property: Dictionary) -> void:
if property.name == "text_node_name":
property.hint = PROPERTY_HINT_ENUM_SUGGESTION
property.hint_string = _node_name_suggestions()
func _node_name_suggestions() -> String:
if not Engine.is_editor_hint():
return ""
var root := EditorInterface.get_edited_scene_root()
if root == null:
return ""
var names := PackedStringArray()
for n in root.find_children("*", "RichTextLabel", true, false):
names.append(n.name)
return ",".join(names)
Keep in mind it lists nodes from whatever scene is open in the editor, which might not be the object this action ends up on. So it keeps free text too, and the real lookup still happens at runtime off p_owner.
Hopefully that helps!
Thank you for your reply. I will test the method you provided later.
