Setter is not called for exported Texture2D var

Godot Version

4.3

Question

Hi,

I’ve got a tool script with exported variables. I’m trying to run a method everytime a texture is changed, but the setter is not called when I update the texture in the editor.

@tool
extends Node
class_name Level

@export_range(16, 128) var level_size: int = 32 :
	set (value):
		print_debug("update level")
		level_size = value
@export_color_no_alpha var color: Color:
	set (value):
		print_debug("update color")
		color = value
@export var heightmap_texture: Texture2D:
	set (value):
		print_debug("update terrain")
		heightmap_texture = value

For the texture, I set a NoiseTexture2D in the editor.

Now, everytime I update the level size, or the color property, the corresponding getter is called. But for the texture, the setter is only called when the scene is initialized, or if I clear the property and set it again from scratch.

If I update a single property of the nexture (changing noise parameters, changing texture size, or any of the texture properties like “seamless”, “normalize”, etc.) the setter is not called.

Is this a bug or an expected behaviour? How can I react to any change in the texture?

Thanks

This is expected behaviour, since you are not changing the reference to the texture, just changing parameters of the texture-resource.

To react to changes inside the texture you might have to create a resource-script which inherits the NoiseTexture2D class and make it a tool_script and override the setter methods.
Or export a boolean inside your Level-script and when its set to true it checks for changes

Mmm…, thank you for your answer, it’s very clear. I will try the methods you suggest.