Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug PropertyFields don't work properly with SerializeReference Fields?

Discussion in 'UI Toolkit' started by Albarnie, Dec 19, 2019.

  1. Albarnie

    Albarnie

    Joined:
    Oct 24, 2015
    Posts:
    18
    I've recently been converting a node editor i created to UIElements and SerializeReference, to clean up the and separate the UI code and to reduce the reliance on ScriptableObjects as having an asset or subAsset per node is not ideal.
    I've tried using Propertyfields with a couple of SerializeReference fields, and it was working fine except the propertyField does not update when the reference changes, only when the UI itself is created. ChangeEvents are also not registered as far as i know.
    But, in case i am wrong, as I am fairly new to UIElements:

    Does ChangeEvent register for SerializeReference Fields? if so, what is the type?
    Is there a workaround to force the propertyField to refresh without a reference to it? i.e through a callback or automatically.
    Is there a field type i can use with SerializeReference Fields?

    If not, please fix this real soon as this firmly halts my ability to use my node editor, i foolishly thought this would be a simple thing.
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    To confirm, UIElements does not yet support SerializeReference. That said, you can still manually handle the reference changes using the SerializedObject/SerializedProperty APIs and manually update and listen for changes on a regular UI ObjectField. You just can't use the built-in bindings support of UIElements.

    EDIT: This actually should work in UIElements but there might be a bug preventing it from working. See post below.
     
    Last edited: Jan 22, 2020
  3. MartinBarrette

    MartinBarrette

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    26
    Which version of Unity are you using? There were some changes in the latest build of 2019.3 when manipulating SerializedField of SerializeReference instance value which might have affected this.
    If it is still reproducible, could you share/report the failing case? Thank you!
     
  4. Albarnie

    Albarnie

    Joined:
    Oct 24, 2015
    Posts:
    18
    I was using 2019.3.0f1 I think, I am currently using 2019.3.0f5
    I am able to work around the issue using a custom delegate that calls BindProperty() every time the value is changed.

    In terms of reproducing, the current project/plugin I am working on is rather large, I'm guessing you'd want to see the issue in a enclosed space? I can do that if it'd help find the issue.

    Thanks

    Edit: I realize i can now use the scheduler to rebind the property every 100 ms or so. this removes the jank but the underlying issue is still there
    Edit 2: ...but it breaks functionality for editing sub fields
     
    Last edited: Jan 22, 2020
  5. MartinBarrette

    MartinBarrette

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    26
    Certainly enclosed space would be ideal if possible. Thank you!
     
  6. Albarnie

    Albarnie

    Joined:
    Oct 24, 2015
    Posts:
    18
    After testing this in an enclosed space I've only been confused further as it seemed to work fine at first. The propertyFields Freeze after the SerializeReference property they are bound to changes type. Rebinding the field to the property updates and unfreezes it.

    I've uploaded a project file which showcases the issue. Inside the project is a single scene which contains a gameObject with a test script attached. there is 3 buttons, two of which switch between references to some made up classes, and the third which rebinds the propertyField displaying the current selected reference.
    upload_2020-1-24_19-23-25.png
    if you switch between the two, you will notice that while the main values update, the values inside the sub class get frozen, and are only updated when you rebind the property with the "Rebind property" button.

    I hope this helps!
     

    Attached Files:

  7. MartinBarrette

    MartinBarrette

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    26
    We were able to re
    Thank you for the sample we were able to reproduce and are investigating.
     
  8. unity_Etienne

    unity_Etienne

    Unity Technologies

    Joined:
    Nov 28, 2019
    Posts:
    17
  9. ShervinM

    ShervinM

    Joined:
    Sep 16, 2017
    Posts:
    67
    Any update on this? Or at least a work around?
     
  10. billykater

    billykater

    Joined:
    Mar 12, 2011
    Posts:
    329
    I would also like an update on when this might be supported (And more broadly expanding editor bindings as someone from unity mentioned). A lot of stuff can finally be implemented through unity serialization that would otherwise be impossible without polymorphism but we can't really do UIToolkit inspectors (especially supporting undo/redo for designers) for them.

    @ShervinM
    One "horrible" workaround that seems to work for us is to have an array with a serialize reference entry in it. Then you can emulate set / unset by adding the reference to the array and removing it which will also allow you to register a callback on array.size change to support undo / redo.

    From another thread I created @oscarAbraham was pointing out some of his workarounds which use some of the internal unity stuff and are also a good read to give you ideas for workarounds. https://github.com/OscarAbraham/UITKEditorAid
     
  11. silentslack

    silentslack

    Joined:
    Apr 5, 2013
    Posts:
    391
    Seems to be fixed in 2022.1 but we need in 2020 LTS. Our PropertyFields for [SerializeReference] don't render.

    Can the fix be applied into the 2020 LTS build of Unity?
     
    LazloBonin likes this.