UnityEvent NullreferenceException in inspector
I'm getting an error whenever I try to add an Event to a UnityEvent field in the inspector (clicking on the plus symbol in the corner). Whenever I hit the I'm running Unity 5.5.0f3 and have tried restarting Unity several times. It's not happening to all UnityEvents I'm using, just these ones, that are in a serializable class rather deep in the object hierarchy. Could the problem be that the definition is too deep in the object hierarchy? I have a Monobehaviour that has a serializable-class variable, that has a list of another serializable-class variable that contains a list of type customEvent.
The code:
[System.Serializable]
public class customEvent
{
public List<GameEvent> events;
public UnityEvent selfdefinedEvents;
public void Invoke(room_controller rooms)
{
foreach (GameEvent ge in events)
{
ge.Invoke(rooms);
}
selfdefinedEvents.Invoke();
}
}
The error: NullReferenceException: Object reference not set to an instance of an object UnityEditorInternal.UnityEventDrawer.AddEventListener (UnityEditorInternal.ReorderableList list) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/UnityEventDrawer.cs:365) UnityEditorInternal.ReorderableList+Defaults.DrawFooter (Rect rect, UnityEditorInternal.ReorderableList list) (at /Users/builduser/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:105) UnityEditorInternal.ReorderableList.DoListFooter (Rect footerRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:627) UnityEditorInternal.ReorderableList.DoList (Rect rect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:400) UnityEditorInternal.UnityEventDrawer.OnGUI (Rect position) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/UnityEventDrawer.cs:157) UnityEditorInternal.UnityEventDrawer.OnGUI (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/UnityEventDrawer.cs:123) UnityEditor.PropertyDrawer.OnGUISafe (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at /Users/builduser/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyDrawer.cs:23) UnityEditor.PropertyHandler.OnGUI (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren) (at /Users/builduser/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:134) UnityEditor.EditorGUI.PropertyFieldInternal (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren) (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorGUI.cs:5158) UnityEditor.EditorGUI.PropertyField (Rect position, UnityEditor.SerializedProperty property, Boolean includeChildren) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/editor/EditorGUIBindings.gen.cs:1041) UnityEditor.EditorGUI.PropertyField (Rect position, UnityEditor.SerializedProperty property) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/editor/EditorGUIBindings.gen.cs:1036) UnityEditor.Editor.OptimizedInspectorGUIImplementation (Rect contentRect) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/editor/EditorBindings.gen.cs:233) UnityEditor.GenericInspector.OnOptimizedInspectorGUI (Rect contentRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/GenericInspector.cs:33) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1216) UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1031) UnityEditor.InspectorWindow.OnGUI () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:356) System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Did you ever manage to fix this? I'm having the exact same problem right now.
I'm also now experiencing this issue. I've been using custom UnityEvents for a long time now and this is the first time I've run into this error.
For me, it's happening from referencing a struct with 2 UnityEvents [Defined in another script] from a fairly deeply nested set of structs (So a very similar setup to what you've got). It's a complicated bit of code for a compiler so I understand why it may be freaking out but exactly one layer up in the set of arrays, it works perfectly fine.
Seems to be an issue with the Editor drawing nested arrays of objects with Events at the bottom for some reason.
Hopefully someone comes along and helps with this extremely specific (and thus easily overlooked) issue.
[Unity 2017.3.0f3]
I know this is old but I'm having the same problem : (
Edit: nvm
Your answer
Follow this Question
Related Questions
UnityEvent Generic (Inspector Serialization) 0 Answers
Event NullReferenceException 1 Answer
How do I keep methods being called until the current one has finished running 0 Answers
Count and find NON-PERSISTENT UnityEvent listeners: How? 1 Answer
ScrollBar and scrollrect seem not working on mobile 0 Answers