React to any property changed on Node

Godot Version

4.5.1.stable

Question

I’m creating a few tool nodes that can be configured extensively, and because of this, I’d like them to automatically update their name property when any changes are made to said nodes.

For example, in my MapGenerator addon, I have a node that repeats children nodes x amount of times. The goal is to apply the repitition count to the name of the node, something like:

func _on_property_changed() -> void:
   self.name = "Repeater_%sx" % repitition_count

The issue I’m having, is how to actually trigger the _on_property_changed() function I’ve defined here.

I know I can use setters, but I’d like to stay away from typing a billion different functions for simply triggering this reaction… there has to be another way, right?

I’ve also considered using _get_configuration_warnings(), but this method seems to only get called when things like scene tree position change.

Anyway, any help would be greatly appreciated! :slight_smile:

Look at EditorInspector signals.

Queble? Wow. this is unexpected :partying_face:

But to be serious. You can use a setter in your export variable and when a value is set. you make the variable store the value and call _on_property_changed() which there, it will change it’s name

@tool
extends Node

@export var repetition_count: int:
	set(value):
		repetition_count = value
		_on_property_changed()

func _on_property_changed() -> void:
	name = "Repeater_%sx" % repetition_count

1 Like

Here’s a little demo as well:

@tool
extends Node

func _ready():
	var inspector = EditorInterface.get_inspector()
	inspector.property_edited.connect(
		func(prop): 
			print("EDITED: %s.%s"%[inspector.get_edited_object().name, prop]) 	
	)

Hey! This is actually what I was doing before, but I’m trying to stay away from this approach so that I don’t have to create a bunch of setters for every property of my nodes :confused:

Oh awesome thanks!

I had no clue about that signal!

2 Likes

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