Serialize an EventReference for a CustomEditor without a serializedObject

In my unity project I reached a point where I have a custom editor that requires specifically not to use a SerializedObject (in this case AdventureCreator’s custom Actions for ActionList).

I would love to add an EventReference but it is impossible since it requires a serializeObject or requires the field to be an object:

``
SerializedObject obj = new(this);
SerializedProperty prop = obj.FindProperty("NameOfEventReference");
EditorGUILayout.PropertyField(prop, "Reference"); // X this works but it uses serialized object
``

I though about EditorEventRef, but I can’t seem to find a way to transport that information outside a statement in Runtime. Basicaly, I would need to make use of that EditorEventRef in unity runtime.

How could I do that??

Edit: I’m using FMOD 2.03.06 and Unity 2022.3.30f1

Forget about the “EditorEventRef”, the point of the question is if it is possible to have an EventReference in a custom editor without using a serializedObject.

If you need more information about why I can’t use serializeObject, I can provide it if it makes any difference on the subject.

Hi,

Thank you for sharing the information!

It sounds like ScritableObject might be what you are look for.

Instead of using the SerializedObject, you could store the EventReference inside a custom ScriptableObject, for example:

 public class FmodEventAsset : ScriptableObject
{
    public FMODUnity.EventReference reference;
}

Then, reference this ScriptableObject in your Action class (assuming it supports UnityEngine.Object references):

public class MyAcAction
{
    public FmodEventAsset eventAsset;

    public FMODUnity.EventReference ToEventReference()
    {
        return eventAsset != null ? eventAsset.reference : default;
    }
}

This way, you can still use FMOD’s event picker in the editor, and access the selected EventReference at runtime without relying on SerializedObject.

Hope this helps! Let me know if it works.

Hello, thank you for your response!

This is a half solution because it does work, but it adds another extra layer to the process of adding an EventReference. This would be creating a ScriptableObject for each reference I want to asign instead of choosing it directly in the custom editor.

Isn’t there a way to reference directly the Custom Editor of EventReference?

Otherwise I guess the last solution would be asking you for the new feature on the next FMOD Unity update. Something like: “FMODUnityEditor.FMODEventReferenceField();”

Thank you for your attention!

As far as I know, there isn’t currently a way to directly reference the Custom Editor of EventReference without using a SerializedObject.

Since I am not familiar with the Adventure Creator plugin, could you please elaborate a bit more on why you can’t use serializeObject?

If your workflow doesn’t necessarily rely on the event picker window, using the event path string could be a simpler alternative as RuntimeManager.CreateInstance() also accepts event paths (e.g. “event:/Music/Level1”), which can be stored and referenced at runtime.

AdventureCreator (forward as AC) is a 2D Point and Click Unity plugin that has a built-in node system, similar to the default unity’s animator. This AC node system is called “ActionList”, which contain different actions inside connected with nodes to make things happen in the game. ActionLists are a component you can place in a gameobject.

This could be one ActionList with different actions inside (i searched one image in google).

AC allows you to create custom Actions (those windows) deriving from the AC class “AC.Action”, which derive from ScriptableObject primarily. It is like a “CustomEditor” but you are not provided with the parameters of a custom editor (serialized property, position, etc…), and even the same AC gives their own functions to generate each GUI that unity gives by default (Sliders, Toggles, Buttons…).

Given the nature of AC system colliding with unity’s serialization, it is very sensitive with serialized properties inside its own class, and as it is possible to serialize properties inside the Action class, it has some problems. One of it is reseting all the values of the whole Action when a SerializedProperty field is modified. This is because AC, for each modification, must “delete” and “recreate” the Action again (or that is what I assumed by extensive debug).

The only way to create a serialized object in an action is by:

OnEnable()
{
    _serializedObject = new(this);
}

ShowGUI()
{
    var property = _serializedObject.FindProperty("EventReference");
    EditorGUILayout.PropertyField(property);
}

As you can see, if this Action is deleted and recreated, the serializedObject is renewed, making the whole object be 0. (Only for the parameters that use this serializedObject).

When I found out about this problem, I changed all the GUI I was displaying for the AC default functions or Unity’s GUI (the ones that doesn’t rely on serialized objects), and everything worked perfectly. But of course, EventReference isn’t something I can display without the use of a SerializedProperty.

I would love to rely on the original CustomEditor Event Picker from EventReference if possible, but if its not possible I can use the string method. It is a strange case, because the custom editor works and it displays correctly but when used then it resets.

Thank you for the detailed explanation, that really helps clarify the use case.

I’ve submitted a feature request to our dev team for further review, and will update you once there’s any progress to share.

Thank you for your attention and your williness to help me out, despite wether the feature request ends up in the next update or not!

1 Like