How to use setget with @tool to change size and print

Godot Version

4.2.1

Question

I have the following code:

@tool
extends Panel

@onready var board_background: Panel = $Grid/Background

@export_subgroup("Board Size")
@export var width = 300:
	# Update width and reset the rotation.
	set(width):
		width = width
		set_size(Vector2(width, height))
		print(get_rect())
		
@export var height = 300:
	# Update width and reset the rotation.
	set(height):
		height = height
		set_size(Vector2(width, height))
		print(get_rect())

This works as expected only in Play mode, but I would like this to work while in my editor to be able to change the width of my component and print it without needing to Play. I am pretty new to Godot so am unsure if I am missing something about the @tool annotation.

You may have to add a type for the variable. It might be showing an error which stops it working in-editor.

@export var width:float = 300:
1 Like

Thank you, this worked!

1 Like