how could I achieve an event OnValueChanged for a scriptable object field?
for example I would like to have a scriptableobject with a WalkingSpeed value, and changing it at runtime on the object would also change it on my movement script.
I load the object using resources.load because I don't know which scriptable object to load until runtime.
I tried just regular on value changed but it seems like unity creates a copy of the scriptableobject in memory so I cannot change the object from the editor.
in the scriptable object:
public float WalkingSpeed = 5f;
public float walkingSpeed
{
get => WalkingSpeed;
set
{
if (Mathf.Approximately(WalkingSpeed, value)) return;
WalkingSpeed = value;
OnWalkingSpeedChanged?.Invoke(value);
}
}
from movement script:
LocalData = player.GetData("Walking");
LocalData.OnWalkingSpeedChanged += newWalkingSpeed => Debug.Log(newWalkingSpeed);