Godot Version
v4.3.stable.mono.arch_linux
Question
Hi, I’m creating a custom Resource, and I have code like the following:
[GlobalClass, Tool]
public partial class AmmoData : Resource
{
[Export]
public ProjectileType ProjectileType { get; set; }
[Export]
public uint PelletCount { get; set; }
public override void _ValidateProperty(Dictionary property)
{
if (property["name"].AsStringName() == PropertyName.PelletCount)
{
var propertyUsageFlags = property["usage"].As<PropertyUsageFlags>();
if (ProjectileType == ProjectileType.Bullet)
{
propertyUsageFlags |= PropertyUsageFlags.ReadOnly;
}
else
{
propertyUsageFlags &= ~PropertyUsageFlags.ReadOnly;
}
property["usage"] = (int)propertyUsageFlags;
base._ValidateProperty(property);
}
}
}
The logic behind this code is “if a user sets ProjectileType
value to Bullet
- make PelletCount
readonly. Otherwise, allow a user to edit PelletCount
”.
Provided code kinda works, but it checks properties and applies logic from _ValidateProperty
only when code is rebuilt. I want this validation logic to be executed on every change of ProjectileType
property (or on the change of any property of my resource).