Search Unity

Bug Renaming custom node class destroys whole graph

Discussion in 'Visual Scripting' started by JacobFast, Apr 17, 2022.

  1. JacobFast

    JacobFast

    Joined:
    Apr 29, 2014
    Posts:
    47
    Create a custom node script (example "public class ExampleNode : Unit { ... ")
    Use it in any graph state/script/embed/not embed
    Rename node class ("public class ExampleNode : Unit" => "public class NodeExample : Unit")
    Console throws serialization error


    Failed to deserialize scriptable object.
    System.Runtime.Serialization.SerializationException: Deserialization into 'Unity.VisualScripting.ScriptGraphAsset' failed. ---> System.InvalidOperationException: Internal Deserialization Error - Object definition has not been encountered for object with id=22; have you reordered or modified the serialized data? If this is an issue with an unmodified Full Serializer implementation and unmodified serialization data, please report an issue with an included test case.


    Graph reset to empty state. Unrecoverable. Regenerate Nodes does not change anything.
    Unity 2021.3 LTS, Visual scripting 1.7.7

    Expectations: Custom node marked as broken, everything else without changes
     
    Last edited: Apr 17, 2022
  2. JacobFast

    JacobFast

    Joined:
    Apr 29, 2014
    Posts:
    47
    Attached screenshots, before and after class rename. Regenerate nodes does not change anything.
     

    Attached Files:

  3. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,072
    That's how it goes with custom nodes. The workflow was never well supported as the tool was primarily marketed towards Unity newbies with no C# knowledge. UVS has inherited those fundamental issues from Bolt 1.

    Did you try decorating the class with [RenamedFrom("OldClassName")] attribute?
     
  4. JacobFast

    JacobFast

    Joined:
    Apr 29, 2014
    Posts:
    47
    Found the solution: After reverting to old class name -> Restart unity. It should recover graph. The graph getting reset not due to data loss, but because the error causes graph instance completely crash for this unity session.
     
    Last edited: Apr 17, 2022
  5. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,072
    Oh, yeah. Fixing the custom node will recover the graph in most cases. It's just not particularly friendly to refactoring efforts. RenamedFrom can be a lifesaver.
     
    Last edited: Apr 17, 2022
  6. JacobFast

    JacobFast

    Joined:
    Apr 29, 2014
    Posts:
    47
    For whoever on unity team do the bug tracking. Though the solution above worked for embed graph, it does not work for script state graph if used inside state machine, if node class renamed the graph is dead, for sure, renamedfrom, renaming class to original name, node regeneration, nothing can recover graph if scene was saved or node regeneration used after class name change and recompilation, graph asset file just reset from 20kb to 1kb, 100% data loss. Only option is use version control and discard the changes.

    so the solution if renaming needs to be done: create a copy of node class with new name, replace all nodes that uses old name with new, then delete old class.
     
    Last edited: Apr 20, 2022
  7. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    167