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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question Save data that has been modified via call to method from UIBuilder button

Discussion in 'UI Toolkit' started by shmomo, Jun 29, 2023.

  1. shmomo

    shmomo

    Joined:
    Oct 11, 2011
    Posts:
    127
    Pressing button (labeled '1') calls a method in the 'Pool' script that populates the array values (labeled '2').
    This works but when I reload the asset in the project window the values return to previous un-modified ones. I used to call serializedObject.ApplyModifiedProperties(); in my OnInspectorGUI script but that doesnt seem to work in the new ClickEvent method in my new UIBuilder script.

    How do I save those changed values using the UIBuilder?
     

    Attached Files:

  2. shmomo

    shmomo

    Joined:
    Oct 11, 2011
    Posts:
    127
    Simply put...

    - I click a button on a custom inspector created with UIBuilder.
    - It calls a method in the script that custom inspector is for.
    - The values for the properties modified by the method do change in the inspector.
    - But they dont 'save'. When I reload the asset the value revert.
    - How can I make them save?

    If I add an int variable and change that value in the inspector it does then save the object but this seems like a crappy workaround and solve if I need to modify multiple objects via an editor window button.
     
    Last edited: Jun 29, 2023
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,942
    Hard to say without seeing code.

    If you're changing values via serialised properties, the dirtying should be handled automatically.

    If you're just directly interfacing with the fields/properties of an object, you need to manually dirty the object so Unity knows values have changed.
     
  4. shmomo

    shmomo

    Joined:
    Oct 11, 2011
    Posts:
    127
    SetDirty! You absolute beaut. Works. Thought I had tried that.