Reputation: 1281
I am building a simple health bar using ColorRect nodes and I want to test that my script is working without running the project. I'm using a Tool script, however changing the values in the editor doesn't affect the size of the ColorRect. If I run the scene using F6 the script runs properly.
using Godot;
[Tool]
public class HealthBar : Control
{
[Export]
private float _maxHealth = 100;
[Export]
private float _health = 100;
private ColorRect _backgroundRect;
private ColorRect _healthRect;
public override void _Ready()
{
base._Ready();
_backgroundRect = this.GetExpectedNode<ColorRect>("Background");
_healthRect = this.GetExpectedNode<ColorRect>("Health");
if (_maxHealth < 1)
{
_maxHealth = 1;
}
}
public override void _Process(float delta)
{
base._Process(delta);
var maxWidth = _backgroundRect.RectSize.x;
var healthPercentage = _health / _maxHealth;
var healthWidth = maxWidth * healthPercentage;
_healthRect.RectSize = new Vector2(healthWidth, _healthRect.RectSize.y);
}
}
Am I doing something wrong or is this a known bug with Tool scripts in Godot?
(Godot version: 3.5.1.stable.mono
)
Upvotes: 0
Views: 457
Reputation: 1281
Ah, I simply needed to close and re-open the tab and it's working now.
Upvotes: 0