Control DirectionalLight3D rotation in editor via script parameters

Godot Version

4.7.2

Question

I have a GDscript attached to a DirectionalLight3D that sets its rotation values at runtime based on date/time/location parameters (see screenshot below).

Is it possible to set the rotation values via script directly in the editor?

What I would like to happen is to see the light orientation update along with a parameter value change while I’m editing the scene (for example: setting a different hour of the day immediately changes the light orientation)

Use a tool script. Those run in the editor.

I thought about it, but wouldn’t the script need to be executed manually (maybe I can add a button in the interface to call the script in order to make changes)? Is there any way to skip this operation and have changes happening in real time?

How about @exports with setters in your tool script?

Yes, just implement _process() and that will be called automatically every frame or put update code in setters. Those will run when you change the corresponding property in the inspector.

@hatmix @normalized thank you for your suggestions! @export with setters did the trick. The only caveat is that, since angles must be computed from all inputs, I have to call the same setAngles function from all setters. This is how things look like now:

@tool
extends DirectionalLight3D

var angles : Vector2
@export var latitude : float = 42.5:
	set(value):
		latitude = value
		setAngles(year,month,day,hour,minutes,UTC,latitude,longitude)
@export var longitude : float = 11.7:
	set(value):
		longitude = value
		setAngles(year,month,day,hour,minutes,UTC,latitude,longitude)
@export var year : int = 2026:
	set(value):
		year = value
		setAngles(year,month,day,hour,minutes,UTC,latitude,longitude)
@export_range(1,12) var month : int = 11:
	set(value):
		month = value
		setAngles(year,month,day,hour,minutes,UTC,latitude,longitude)
@export_range(1,31) var day: int = 20:
	set(value):
		day = value
		setAngles(year,month,day,hour,minutes,UTC,latitude,longitude)
@export_range(8,22) var hour : int = 9:
	set(value):
		hour = value
		setAngles(year,month,day,hour,minutes,UTC,latitude,longitude)
@export_range(0,59) var minutes : int = 0:
	set(value):
		minutes = value
		setAngles(year,month,day,hour,minutes,UTC,latitude,longitude)
@export_range(-11,11) var UTC : int = 1:
	set(value):
		UTC = value
		setAngles(year,month,day,hour,minutes,UTC,latitude,longitude)