Detect the `Color` change in a @Tool script

Godot Version

4.3

Question

I have a custom node with two MeshInstance2D nodes with my custom shader attached.

In the root node I’ve created the color property so that I can modify the color uniform of my two MeshInstance2D shader materials in one place.

The color is set properly when I run the test scene, however, it’s not updated live in the editor when I change the color in the inspector.

It seems like the setter never runs if I change the property in the editor:

@tool

class_name Shroom extends Node2D

@export var color : Color = Color( 1 , 1 , 1 , 1 ) :
  get : return color
  set( value ) :
    color = value
    set_color( value )

@onready var base : MeshInstance2D = $Base
@onready var core : MeshInstance2D = $Core


func _enter_tree() -> void :
  property_list_changed.connect( func () : print( "hello" ) )

func _ready() -> void :
  set_color( color )

func set_color( ncolor : Color ) -> void :
  var baseL : MeshInstance2D = base if base else get_node_or_null( "Base" ) as MeshInstance2D
  var coreL : MeshInstance2D = core if core else get_node_or_null( "Core" ) as MeshInstance2D

  var base_shader : ShaderMaterial = baseL.material if baseL else null as ShaderMaterial
  var core_shader : ShaderMaterial = coreL.material if coreL else null as ShaderMaterial

  if base_shader :
    base_shader.set_shader_parameter( "color" , ncolor )
    baseL.material = base_shader

  if core_shader :
    core_shader.set_shader_parameter( "color" , ncolor )
    coreL.material = core_shader

It suddenly started working after I’ve restarted the editor. The time I’ve wasted… -.-

Wasted time is a programmer’s paradise. :smile:

@tool setters don’t work for me until I close and reopen the scene. I wonder if there is a way to refresh the scene without having to close it.