• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
2
Question by retraffic · Jan 18, 2017 at 12:01 PM · inspectornullreferenceexceptioneventsystemevents

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.

Selfdefined Events UnityEvent field in inspector gif version

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)

unityerror.jpg (45.7 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image PedroCoriAG · Jul 18, 2017 at 06:55 PM 0
Share

Did you ever manage to fix this? I'm having the exact same problem right now.

avatar image KylBot · Dec 27, 2017 at 11:36 PM 0
Share

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]

avatar image shadowjet323 · Apr 19, 2019 at 10:46 PM 0
Share

I know this is old but I'm having the same problem : (

Edit: nvm

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

93 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UnityEvent Generic (Inspector Serialization) 0 Answers

Is it possible to make custom automatically-called methods like Start and Update? 0 Answers

Convert Event.current.mousePosition to Input.mousePosition 0 Answers

Way to assign event fields in created at runtime scriptable object (ScriptableObject Architecture) 0 Answers

Animation Event not firing or skip problem (When Fast Animation) 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges