Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@tool functionality doesn't take effect until reloading the project. #95268

Open
Vallith opened this issue Aug 8, 2024 · 3 comments · May be fixed by #92099
Open

@tool functionality doesn't take effect until reloading the project. #95268

Vallith opened this issue Aug 8, 2024 · 3 comments · May be fixed by #92099

Comments

@Vallith
Copy link

Vallith commented Aug 8, 2024

Tested versions

Tested in v4.2.2.stable.mono.official [15073af]

System information

Godot v4.2.2.stable.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3080 Ti (NVIDIA; 32.0.15.5585) - AMD Ryzen 7 5800X 8-Core Processor (16 Threads)

Issue description

When editing a script to include @tool to reflect visual changes in a parent/sibling component, no changes are seen until I reload the project.

I have this simple script:

@tool
extends Node2D

@export var sprite : Sprite2D
@export var colour : Color :
	get:
		return colour
	set(value):
		colour = value
		if is_node_ready():
			sprite.self_modulate = colour

The first time I add this script to a Node2D after writing it, and modify the colour - I don't see the colour of the sprite change until I reload the project. However, after reloading I can remove the script and re-add it to the same or a different node and it will continue to work. It's only the first time I try to use the script after writing it does the issue occur. Deleting the script, creating a new one, and pasting the exact same code in will also make the issue occur again.

Steps to reproduce

  1. Create a new project with a Node2D as the root.
  2. Add a Sprite, set to the default icon.svg.
  3. Add a Node2D and attach a script to it.
  4. Put this in the script:
@tool
extends Node2D

@export var sprite : Sprite2D
@export var colour : Color :
	get:
		return colour
	set(value):
		colour = value
		if is_node_ready():
			sprite.self_modulate = colour
  1. Drag Sprite into the exported field on the Node2D
  2. Change the exported colour variable on the Node2D and see that it doesn't affect the sprite.
  3. Go to Project > Reload Current Project
  4. Change the colour variable again and see that it does now affect the sprite.

Additionally:
9. Detach the script from the node, and delete it.
10. Attach a new script to the node, add the same script.
11. Drag the sprite back into the field.
12. Change the colour, and it isn't affecting the sprite again.

Minimal reproduction project (MRP)

This is simple enough to recreate and given that it seems to depend on things being used/written for the first time I don't think it's necessary I provide a project.

@dalexeev
Copy link
Member

dalexeev commented Aug 8, 2024

As far as I remember, it should be enough to restart only the scene, not the whole editor. For resources, you may need to restart the editor if the resource has many references and therefore will not be unloaded when you close a single scene.

@4X3L82
Copy link

4X3L82 commented Aug 8, 2024

Just close the scene and reopen it, your (visual) changes will be there.

The same goes for if you use any draw_*() functions.

@KoBeWi
Copy link
Member

KoBeWi commented Aug 8, 2024

My guess is that ScriptInstance is only created when a node is initialized, and it only happens when the script is @tool. Thus changing it after the node was initialized won't take effect.

btw, for draw() you can simply toggle visibility twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Fix pending review
Development

Successfully merging a pull request may close this issue.

4 participants