0 votes

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?

Godot version 3.5
in Engine by (12 points)

tool script will never reach ready() when in editor.
You can use setget function of your exported values to display and calculate your logic whenever exported value is changed.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.