I'm working on a re-usable scene and struggling with what must be a basic pattern in my node hierarchy.
I want to be able to set some values on the root node via the editor (using export
vars) and then use those values (plus some additional internal logic) to set the values of child object properties, like the radii of its collision shapes. I'd also like to have these changes visible in the editor for easy debugging.
This script kinda works, but changes only appear in the editor only appear after closing and reopening the tab.
tool
extends Area2D
export var hitbox_radius: float = 10.0
export var hurtbox_radius: float = 10.0
onready var first_collision_shape = $FirstCollisionShape
onready var second_collision_shape = $SecondCollisionShape
func _ready() -> void:
first_collision_shape.shape.radius = hitbox_radius
second_collision_shape.shape.radius = hurtbox_radius
I feel like I must be missing a basic pattern here. Is there a better way to achieve this?