Open Source Observable<T> and ObservableList<T> implementation that integrates perfectly with Unity.

I have open sourced an implementation of Observable and ObservableList for Unity. Observables allow you to have public fields in your classes that fire events when they are changed. Its a very useful pattern, you no longer need to check if a value has changed each frame in an Update() call.

The goal for this implementation is to keep it simple and integrate it seamlessly with the Unity editor. The observables are serializable and display nicely in the editor. They may be used in runtime scripts or editor scripts. They fire change events due to changes made in the inspector or the UNDO system (this part was quite challenging).

I love to use observables in Unity. They make it much easier to write components that are robust to their public variables being changed at any time. I spent a good while looking for Observable implementations in various forums and blog posts, but none of them integrated perfectly with Unity as listed above. I spent a few days combining these examples and extending them. The scripts are available for free if you may find them useful.

https://github.com/Adam4lexander/UnityObservables

3 Likes

Neat, I shall go observe what you have done.

1 Like

Looks cool! If feasible, I wonder if this might benefit from the addition of a custom property drawer with UnityEvents for the observable events?

Yeah it should only need a bit of tweaking to have a version based on UnityEvents. Im thinking of making a version like that too.

1 Like