StableEnum or: How I Learned to Stop Worrying and Love the Enums in Unity3d

It’s a well-known problem with serialization of enums in Unity3d:

  1. Use enum as a serialized field in your MonoBehaviour or ScriptableObject (or anything serializable).
  2. Fine-tune everything and code your game further casually.
  3. Add some new enumerators in the middle of your enum.
  4. BAM!! You are screwed.

What happened? Nothing fancy: new enumerators of your enum just shifted down the old ones occupying their values, because Unity serializes enums as ints.
Solution is easy: serialize enums as strings. And StableEnum will help you with this.

Share Comments
comments powered by Disqus