Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug PropertyDrawer - Exiting PlayMode - ArgumentNullException: Value cannot be null

Discussion in 'UI Toolkit' started by Doomchecker, Dec 5, 2022.

  1. Doomchecker

    Doomchecker

    Joined:
    Apr 5, 2021
    Posts:
    105
    Unity 2022.2.0b16 URP

    PropertyDrawer
    Code (CSharp):
    1.  
    2.  
    3. private SerializedProperty getObjectProperty;
    4. private EnumField getObject = new();
    5.  
    6.        public override VisualElement CreatePropertyGUI(SerializedProperty property)
    7.         {
    8. getObjectProperty = property.FindPropertyRelative("getObject");
    9. getObject.BindProperty(getObjectProperty);
    10. container.Add(getObject);
    11.             return container;
    12.         }
    Works fine in the Editor but when having the inspector open and leaving play-mode, I get this:
    upload_2022-12-5_11-24-29.png


    I tried to solve it with null-checks but the problem is that the serializedObject is recognized when checked directy, in the next line the error appears again.
    Code (CSharp):
    1.             if (property.serializedObject == null) return;
    2.             if (property.serializedObject.targetObject == null) return;
    Anything I can do?
     
  2. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    Could you post the whole stack trace of the error?
     
  3. Doomchecker

    Doomchecker

    Joined:
    Apr 5, 2021
    Posts:
    105
    For some reason the error message just disappeared.
    It has been there for days including multiple restarts and code-changes.

    Thanks for your reply, will post again in case it comes back.