Search Unity

View data persistence with ObjectField

Discussion in 'UI Toolkit' started by 5argon, Nov 11, 2019.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I have set the "view data key" of my ObjectField. On reinstantiating the editor window, the ObjectField was not preserved visually however when I click on it, it pings the correct previously assigned object.

    upload_2019-11-11_17-37-31.png

    Screenshot 2019-11-11 17.35.46.png

    So it seems that view data persistence works, how to make it visually assigned on instantiating the UI the next time?
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    This looks like a bug. Can you please report it using the Report a Bug tool in the Help menu?

    That said, view data persistence is really only meant for view state, not program/tool state, for example: scroll position, foldout expansion state. For remembering the value of a data field, I would use the EditorWindow's own serialized state. So, use a [SerializeField] field in your EditorWindow to remember to current object selection and restore it in the OnEnable() function (or where you recreate your UI). If you want to remember this longer than the window's life, use an asset.
     
    5argon likes this.
  3. iSinner

    iSinner

    Joined:
    Dec 5, 2013
    Posts:
    201
    This is still an issue. More over, i get the same problem with vector2 fields. They show 0,0 in UI, but the values are not 0,0 when i check them in the code.

    Was this not fixed since 2019?

    Unity 2020.3.8f1
     
    Last edited: Jun 7, 2021
  4. cpalma-unity

    cpalma-unity

    Unity Technologies

    Joined:
    Nov 30, 2020
    Posts:
    110
    Hi. I was able to reproduce this issue using a Vector2 field. I just created a ticket for this and I'll post the link to track it whenever is available.

    Thank you.
     
    iSinner likes this.
  5. iSinner

    iSinner

    Joined:
    Dec 5, 2013
    Posts:
    201
    Thanks. Can you inform me on the state of the object field? i have the same effect(bug) as with vector2 fields.

    I open the editor window, set an asset reference into the object field, close the editor window, open it again and the field shows it's empty, but when i click on it, it highlights the asset and if i check it from code, the value is not null.

    It seems that it is bugged as described in the opening post, or am i doing something wrong with it?

    If you can't reproduce it, i can share my files.
     
    Last edited: Jun 8, 2021
  6. cpalma-unity

    cpalma-unity

    Unity Technologies

    Joined:
    Nov 30, 2020
    Posts:
    110