godot: Inspector not running code in `@tool` scripts until restart


Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.


Godot version

4.0 beta 1

System information

Windows 10, Vulkan desktop

Issue description

No script marked as @tool appears to be executing when it is expected by the inspector. Examples I have found are that the set/get functions of properties are not being called and the parse_begin / parse_end functions of inspector plugins are not being called.

Steps to reproduce

  1. Create a new Node3D scene
  2. Attach a script with the following code:
extends Node3D

@export var tester:int:
    get:
        return 100
    set(value):
        print("NEW VALUE ", value)
        tester = value/2
  1. Select your node and change the tester property in the inspector:

Expected: Value of tester to be set to half the input value. “NEW VALUE” should appear in the output log

Result: Value of tester is set to exactly the input value. No change in output log

Minimal reproduction project

ToolBug.zip

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 9
  • Comments: 20 (12 by maintainers)

Most upvoted comments

Can confirm the bug still exists on 4.2 also with GDScript.

@AThousandShips lots of people been running into this, really ought to be documented !!!

@AThousandShips huge thanks, that did the trick.

In case it’s helpful to anyone:

When adding/removing @tool from a script or attaching/detaching a @tooled script to a scene, you must restart the editor to add/remove interactivity in the editor

After restarting, I’m now able to edit the script and see the behavior change immediately without having to restart the editor. But if I create a new scene and attach the same script to it, I have to restart the editor again to get the behavior into the process loop.

This is unfortunately a current limitation which I’m not sure why it is, nor is it documented, can’t find an issue tracking it either

When adding/removing @tool from a script or attaching/detaching a @tooled script to a scene, you must restart the editor to add/remove interactivity in the editor

This shouldn’t be a requirement. Attaching a script should just work, at most you need to reload the scene (especially for previously attached scripts). If this is not the case right now and you need to restart the whole editor, it’s not something to document but rather something to fix.

Importantly, though, does this still happen in 4.1.3 or 4.2 betas?

See also:

  • #81972

    Tested on 3.5.2 The behavior was instantaneous and worked fine. It didn’t require reload of scene or Project

  • #82443

    Reopening the scene also works, not just restarting godot entirely.

Have you restarted the editor?

I was just about to post this for setters. while work around for the int setter above does work, it doesn’t seem to even try, for anything that’s in the tree like a Node3D.

@tool
extends MeshInstance3D

@export var vint:int:
	set(v):	print("int ", v)

@export var vVector3:Vector3:
	set(v): print('Vector3 ',v)

@export var vNode3D:Node3D:
	set(v): print('Node3D ',v) ; vNode3D = v

@export var vResource:Resource:
	set(v): print('Resource ',v) ; vResource = v

everything but the Node3D prints whether you just open the scene or change the setting. this is of course only after closing and reopening the scene after adding the setter.

on run it does. though the Node3D setter fires later in order after other scripts have initialized. which I would assume is exactly right. ex:

CORE API HASH: 2378449490
EDITOR API HASH: 200905626
Loaded builtin certs
int 0
Vector3 (0, 0, 0)
Resource <Texture2D#-9223372010933976765>
set:::: Target:<MeshInstance3D#26088571289>  <-- setter in other script
Node3D Node3d:<Node3D#26105348500>

Through further experimentation, I have found that removing the script from the node and adding it back gets it to work