I am using E-AI and just found out that the Unity Events are not saved when i turn the gameobject into a prefab.
They endup empty.
Usually i would just write a wrapper script and attach, thats fills in what i need, but i am not sure how to assign the function.
Gameobject is a gameobject, pretty clear, but the function, how, is possible would i assign the function and the value box (currently not shown) when the script starts …
You add listeners using Unity - Scripting API: Events.UnityEvent.AddListener but I don’t believe it will populate the serialized listener fields in the inspector when you do that. I don’t think there’s any way to populate those fields via script except via reflection.
The reason is that when you add listeners via AddListener in code, you’re directly adding a C# delegate listener. But the listeners from the UI are a little different. Rather than being direct delegates, they’re a combination of a Unity Object reference and a String method name/argument list. Unity will use its messaging techniques (SendMessage, Invoke) etc… to invoke that type of listener at runtime. They’re not really the same thing.
Anyway, the UnityEvent listeners from the inspector will only go away when you make a prefab if the listening object is not part of the prefab’s own hierarchy. This is for the usual reason you can’t have any references to objects that live in scenes from prefabs. You can still reference objects within the prefab, although I recognize that may not cover your use case.
Ok i learned that event system saves if using the Gameobject itself, so i created a seperate script and added it to the prefab.
That worked, i tested loading, unloading, spawning in multiple using crux,