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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Resolved My custom editor not saving the changes.

Discussion in 'Testing & Automation' started by shunaky, Sep 21, 2020.

  1. shunaky

    shunaky

    Joined:
    Jul 26, 2018
    Posts:
    5
    So... My custom editor works this way:

    Objects involved
    -> Node
    -> Connection (It's like an output from the node, every node has 4 connections)
    -> Branch (An object that is connected to one connection in two different nodes)

    The Editor was created on Node, I can select which Node to connect and where on the node (Connection) to connect.

    When connecting: Create a branch and connect to both connections and changes the variable "connectedBranch" in both connections to this newly created branch.
    View attachment 702846

    This is the newly created branch and the element 0 and 1 are both connections (Arrows) that this branch is connecting.
    View attachment 702852
    And this is the connection, note the branch is currently connected to it.
    View attachment 702855

    But now, let me try clicking on play.
    The branch that was created using the editor keeps working as fine.
    View attachment 702858
    But, the connection node that was just had one of it's variables changed lost all the changes.
    View attachment 702861

    While I'm in the Editor, everything works just fine, with no problems, but when I reopen the scene or play the game these connections loses the branch reference.

    Tried manually through the inspector asign the branch, and it worked, it ONLY happens through the custom Editor.

    Here are the screenshots of the error happening to me.
     
  2. shunaky

    shunaky

    Joined:
    Jul 26, 2018
    Posts:
    5
    After a lot of debugging and searches, I made all these changes

    Added [Serializable] on the NodeConnection class.
    When I modified the object, I used both RecordObject(connection, "reason") and EditorUtility.SetDirty(target)

    at the end of every cicle i added on the editor code serializedObject.ApplyModifiedProperties();

    Now I just need to find out what was useful and what was just wasteful.