I'm using UnityEvent and ScriptableObjects Events to manage some decoupled events. I need to save this .
Now, from reading the forums, I realized that UnityEvent is not serializable and you gave some ideas. I having a hard time understanding how to implement the work around. Would I be able to get some guidance?
How am I using the events:
- I have a ScriptableObject with a UnityEvent (appearing on the inspector)
- I create an Event ScriptableObject that I attach to this UnityEvent
- I add a Listener Object to any object that I want to register, I add this ScriptableObject again and I register whatever method that I want to register
When I load the UnityEvent appears as null (as expected from reading the forums)
For reference the idea that was given was this:
Code: Select all
// To save
ES3.Save( "myEvent", event.GetPersistentMethodName(0) );
// To load
string methodName = ES3.Load<string>("myEvent");
event = new UnityEvent();
if(methodName == "MyMethod")
event.AddListener(MyMethod);
if(methodName == "AnotherMethod")
event.AddListener(AnotherMethod);