I have a custom editor in UIElements, which allows you to select scriptable objects and edit them in the inspector.
How do I get a callback when that object is marked dirty / saved so that I can refresh the custom editor as well?
I have a custom editor in UIElements, which allows you to select scriptable objects and edit them in the inspector.
How do I get a callback when that object is marked dirty / saved so that I can refresh the custom editor as well?
The closest I’ve been able to get is this. However, there is no easy way to get from instanceId to the game object.
ObjectChangeEvents.changesPublished += (ref ObjectChangeEventStream stream) =>
{
Log.Info($"{stream.length}");
for (int i = 0; i < stream.length; ++i)
{
var eventKind = stream.GetEventType(i);
if (eventKind == ObjectChangeKind.ChangeAssetObjectProperties)
{
stream.GetChangeAssetObjectPropertiesEvent(i, out ChangeAssetObjectPropertiesEventArgs data);
// I would have preferred to filter by class type, but...
if (data.instanceId == ActiveTimeline.GetInstanceID())
{
RefreshUI();
}
if (AssetDatabase.GetAssetPath(data.instanceId) == AssetDatabase.GetAssetPath(ActiveTimeline))
{
RefreshUI();
}
}
}
};
Hi, have you looked into the Serialized Property bindings system ?
It handles updating standard fields automatically but also allows you to get callbacks for property changes.
Hope this helps.
I looked at it, but it was a bit convoluted for what I needed. A visual editor that doesn’t map 1:1 with certain elements, so really I just need to know when the asset involved has changed for force a screen refresh.
For example, each of these bars maps to a scriptable object:

There is no direct editing of any values here, so binding makes no sense.
However, dragging the bars around changes the values inside the scriptable object, so if the user edits those fields inside a scriptable object, I need to refresh the UI to keep them in sync. (e.g if you manually change the duration, I want the screen to update immediately)
I don’t immediately see an example to have a ‘generalized’ registration for the object changing via binding.
an example here of the backing objects:
There is a method for observing an entire SerializedObject, which can be created to represent a ScriptabeObject (example).
Now that sounds right on the money! Thank you