[OpenSource] SerializableAction - serialization of any action, even anonymous!

Hi guys,
I’ve developed a serializable action solution that handles most cases of actions, even anonymous:)
So far it only supports parameterless, single-cast actions but it is easily extendable to support other needs.
Anyway, here is my implementation:
Github Gist

Each of the scripts is a wrapper for their respective type they should serialize.
You can use the other classes if you want to add to the functionality. I commented everything to make it a bit more understandable, and expanding on the features should be quite easy.

Features:

  • Supports all serializable objects of both UnityEngine.Object and System.Object
  • For unserializable objects, their serializable fields get serialized, all other get defaulted (one layer only)
  • Support for static methods
  • Supports generic methods or methods in generic classes
  • Supports even anonymous actions! You can fully use the context and reference just about all local variables!

If you find any kind of bug or constellation that does not serialize correctly, please tell me so I can fix it

SerializableAction is the backbone of UndoPro and conversely enables Undo in Node Editor Framework; here’s some more detailed explanation of what UndoPro can do and what not in regards to anonymous functions - the same applies to SerializableAction!
If I ever were to update SerializableAction, I would most likely modify UndoPro and forget about this gist, if that happens please tell me and I’ll update it.

Seneral

2 Likes

Hello, is this still up to date with the latest version of Unity?

You could just use UnityEvent, couldn’t you?

Technically I’m not sure, since I have not maintained the gist link. It is being used in UndoPro though, which in turn is being used in my Node Editor Framework, so yes, not only is it currently working, it likely will receive updates for the forseeable future in case something breaks. I’ll update the gist soon.

Not 100% sure anymore since it was a while ago (few years to be exact) since I developed it, but one of the following was a big problem for me (or maybe all). Rest assured I could NOT have used UnityEvent in UndoPro, for example.

  1. Doesn’t work in editor tools
  2. Doesn’t work with anonymous functions capturing the scope (see this, for example, which is backed by a SerializableAction)

Also sorry for late reply, noticed I’m not (anymore) receiving email updates about this thread…