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 Custom inspector: NullReferenceException when dragging onto a field under an Array.

Discussion in 'UI Toolkit' started by dasgandlaf, Mar 12, 2022.

  1. dasgandlaf

    dasgandlaf

    Joined:
    Aug 13, 2020
    Posts:
    23
    Hi,
    I made a custom inspector:
    Code (CSharp):
    1. [CustomEditor(typeof(FieldNotificationForwarderReceiverMB), true)]
    2. public class FieldNotificationForwarderReceiverMBEditor : Editor
    3. {
    4.     public override VisualElement CreateInspectorGUI()
    5.     {
    6.         VisualElement inspector = new VisualElement();
    7.         InspectorElement.FillDefaultInspector(inspector, serializedObject, this);
    8.         return inspector;
    9.     }
    10. }
    It should draw an array, of an array (Which works). It looks like this:

    upload_2022-3-12_16-45-48.png
    (InstantiateOnEventMB is a child of FieldNotificationForwarderReceiverMB)
    The problem: Whenever dragging an object onto an element inside of an array, it throws a NullReferenceException. When dragging an Object on the "Asd" field (Bottom of the picture), which is outside of an array, it works.
    But, clicking on the circle of an array element and selecting an object does work. Only dragging doesn't.

    I appreciate any help.
    P.s. Please add the functionality of spoilers to threads, so a post with pictures and code isn't so long and intimidating to read through.

    Thanks!
     
    Last edited: Mar 12, 2022
  2. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    515
    Hi!

    I was thinking the same for my own post a minute ago! Yours is still ok (not too long), don't worry. I try to compensate by doing less text and using screenToGif to make a small video/gif, but again keeping the size of the gif under control is hard.


    This seems like a bug, possibly because there is an error in the management of the re-ordeorable list (maybe a mouse event is wrongly used). I would be curious to know if it still happens with that feature disabled, but I think it would only be an (unacceptable) work around.

    Can you fill a bug with this with your project and detailed reproduction steps?
     
  3. dasgandlaf

    dasgandlaf

    Joined:
    Aug 13, 2020
    Posts:
    23
    Hahaha, seems like I'm not the only one with this problem :D

    Once I have time, I'll try to file a bug report.

    Anyways, I just want to add, that the VisualElement system is way better in comparison to the IMGUI system. This might be off-topic, but is there a date at which I could expect UIBuilder to leave pre-release, and to fully release?
     
  4. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    515
    The UI builder is not pre-release, being shipped with unity. What makes you think it is pre-release?
     
  5. dasgandlaf

    dasgandlaf

    Joined:
    Aug 13, 2020
    Posts:
    23
    Sorry, I meant experimental.
     
  6. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    515
    It is not experimental either ;)
     
  7. dasgandlaf

    dasgandlaf

    Joined:
    Aug 13, 2020
    Posts:
    23
    Huh, this is what it shows in the package manager for me:
    upload_2022-3-19_16-8-26.png
    Am I missing something here?
     
  8. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    515
    The builder is also released as part of the editor now, but I think they kept the package up to date/compatible for longer.
     
  9. sebastiend-unity

    sebastiend-unity

    Unity Technologies

    Joined:
    Nov 9, 2015
    Posts:
    183
    Since 21.1, UI Builder has been shipped as a core part of the Editor. This taken from the com.unity.ui.builder README.md:

    2021+: Nothing to do. UI Builder comes built-in in Unity 2021.1+.