[UnityEvent] Remove a lister from a unityEvent in the inspector
Hy everyone,
I have a question about unityEvent. I don't understand how to remove a listener once it has been added from the inspector. I keep a trace of the gameObject function in a UnityAction but when I remove it, nothing happens in the inspector. Is this normal?
Good Day,
Answer by Hellium · Oct 17, 2021 at 09:14 AM
As far as I know, listeners added from the inspector (called persistent listeners) can't be removed by code except editor code, making builds impossible.
If you want to remove callbacks at runtime, you need to add them by code.
However, you can disable persistent listeners by calling yourEvent.SetPersistentListenerState(persistentListenerIndex, UnityEventCallState.Off)
. Then, enable the listener again by calling yourEvent.SetPersistentListenerState(persistentListenerIndex, UnityEventCallState.EditorAndRuntime)
Your answer

Follow this Question
Related Questions
Can i update button listener? 0 Answers
Why i can't see scenes in inspector? 0 Answers
How do I use EditorGUILayout.EnumPopup with an enum with 'holes' in a custom inspector. 3 Answers
Unassigned Reference Exception on an Animator, but Animator is assigned in Inspector? 0 Answers
Custom inspector for items in array. 1 Answer