@tool not working anymore in Godot 4.6?

Godot Version

4.6

Question

So once again I am here with a problem I ran into after upgrading to 4.6. This code was working in 4.5, but in another game that I’m working on in 4.6 it stopped working.

This code is supposed to update the size of the collision area in editor, but it doesn’t. Here it is:

@export_category("Collision Area")
@export var side : SIDE = SIDE.LEFT :
	set(value):
		side = value
		update_area()
@export_range(1, 12, 1, "or_greater") var size : int = 2 :
	set(value):
		size = value
		update_area()
func update_area() -> void:
	var new_rect : Vector2 = Vector2(40, 40)
	var new_position : Vector2 = Vector2.ZERO
	
	if side == SIDE.TOP:
		new_rect.x *= size
		new_position.y -= 20
	elif side == SIDE.BOTTOM:
		new_rect.x *= size
		new_position.y += 20
	elif side == SIDE.LEFT:
		new_rect.y *= size
		new_position.x -= 20
	elif side == SIDE.RIGHT:
		new_rect.y *= size
		new_position.x += 20
		
	if collision_shape:
		collision_shape.shape.size = new_rect
		collision_shape.position = new_position

What could be the reason for this not working anymore?

Does it give an error or something?
Please give more info about the issue.

1 Like

At the end of your setter functions, put notify_property_list_changed()

Try that and report back

3 Likes

So it’s very strange, I rebooted Godot and now it works perfectly. So I guess the problem’s solved.

So after some work on the project, this problem is now back. I now see that in the second part of the code provided in the post, the collision_shape is not visible to Godot for some reason (if I remove the if part, it says that it cannot change the properties of a null value).

I have collision_shape declared as @onready var collision_shape: CollisionShape2D = $CollisionShape2D after the export variables, and it is very much present in the editor. What could be the issue here?