Using @tool in Godot4 for real time property updates in editor - how?

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

Hi all.
I have a multimeshinstance3d node in my scene and I want to see the properties update in real time in the editor when, e.g., I change the instance count in the inspector.

In my code, I loop through the instances and apply transforms to each based on a ‘center’ node, which is just a node3d. Multimesh Instance transforms are set to spawn around this center 3d node. Again, I want to see the instances ‘follow’ the center node as I move it in the editor.

I’m using the @tool keyword at the top. The logic for the multimeshinstance3d is all kept in one function (which does the looping, sets transforms etc). If I put that function in process, it will update real time in editor but it will be very expensive (especially with thousands of multimeshes). What I want to do is somehow detect when the center node is moved in the editor as well as when an export property is changed in the inspector, and only run the function then. How do I do that? I’ve experimented with the property-list_changed signal, but to no avail…

:bust_in_silhouette: Reply From: Zylann

In Godot3 you’d do that with setget but in Godot 4 you could do something like that instead:


@export var center: Vector3:
		return center
		if value != center:
			center = value

I don’t know if the syntax is exact, I dont have the engine to verify, have a look here: GDScript reference — Godot Engine (latest) documentation in English

Another way to go without properties is to remember the previous value of center and detect the change inside _process.

Thanks. I was baffled to see setget gone in 4. I managed to find the relevant docs and got it to work in the interim, although the tip about checking prev property status in process is a good one, why didn’t I think of that…

Anyway, we’re all waiting for you terrain plugin to be updated to Godot 4. Jut saying:)

Macryc | 2022-02-03 13:52