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

ScriptableObject / UVS serialization problem?

Discussion in 'Visual Scripting' started by henkjan, Sep 26, 2022.

  1. henkjan


    Aug 1, 2013
    I've created a custom SwitchUnit that is just an implementation of a SwitchUnit and excepts an InputSO ScriptableObject. This ScriptableObject I use like an enum alternative.

    Code (CSharp):
    1. public class SwitchOnInputSO : SwitchUnit<InputSO>
    2. {}
    Than I've created a new script graph and connected it to a GameObject using a ScriptMachine.

    This all works fine until I restart the unity project.
    I get (random) warnings that some connections could not be loaded. (see VSWarning.png)
    The graph looks like the other image I've added: VSProblem.png

    What can I do to fix this?

    Attached Files:

    Last edited: Sep 27, 2022
  2. REDACT3D_


    Nov 8, 2020
    if you disconnect the red errored lines and connect them back up again manually. does it work until you restart again?
    or is it completely broken even if you re-hook the node connections?

    I feel like it could be altering the key or otherwise changing when you leave and come back
  3. henkjan


    Aug 1, 2013
    I can't connect them directly. If I update the ScriptableObjects (by removing or adding a new one), the switch is reevaluating itself and the correct output arrows are available for connection again. Also the names of the ScriptableObjects items in the list are displayed correctly now.

    To me it looks like the script graph is deserializing before the ScriptableObjects are deserializing.

    update: I did some more testing. When it is broken and I only change the scope of the switch (I have different custom switch units and this one has a base class: UnifiedVariableUnit) it updates itself and reconnects to the right nodes. So it looks like internally the connections are still registered but at Unity startup the SO aren't available when the graph is building itself.

    'I feel like it could be altering the key or otherwise changing when you leave and come back'
    By the way it will only break when I close Unity and start up again.

    I hope this clarifies it a bit :)
    Last edited: Sep 27, 2022
  4. REDACT3D_


    Nov 8, 2020
    When working with Subgraphs, I notice similar behavior when the input or output keys are changed.
    After you enter in the value and apply it with ENTER, the text field grays out and acts like it does not want to be touched. Say for example, if you want to rename the key.

    does it create an empty socket like shown in the image?
    here I refactor the Key from Key2 to 1
    Capture.PNG Capture2.PNG

    are you dynamically setting any of the keys?
    is the script also in the project folder? (i assume it is) sometimes if you drag and drop graphs before the script is in, it'll do this too..
    Last edited: Sep 27, 2022
  5. henkjan


    Aug 1, 2013
    I don't do anything with changing keys.
    The graph is in a file (not embedded) and attachted to an empty GameObject.
    And the scripts are in an Assets/Scripts folder (within the project)

    I've made another sample without the sub graphs. The result is the same. I've attached a screenshot.
    (See also the warnings in the Graph Inspector)

    This is the InputSO code:

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using System.IO;
    3. using UnityEditor;
    4. #endif
    5. using Tsc.RuleSystem.Helpers;
    6. using UnityEngine;
    8. namespace Tsc.RuleSystem.Data
    9. {
    10.     [CreateAssetMenu(fileName = "Input", menuName = "RuleSystem/Input")]
    11.     public class InputSO : ScriptableObject
    12.     {
    13.         [SerializeField]
    14.         public InputType InputType;
    16.         [SerializeField]
    17.         public string Name;
    19. #if UNITY_EDITOR
    20.         private void OnValidate()
    21.         {
    22.             Name = Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(this));
    23.         }
    24. #endif
    26.         public override string ToString()
    27.         {
    28.             return Name;
    29.         }
    30.     }
    31. }
    And this is the SwitchOnInputSO code:

    Code (CSharp):
    1. using Tsc.RuleSystem.Data;
    2. using Tsc.RuleSystem.Helpers;
    3. using Unity.VisualScripting;
    5. namespace Tsc.RuleSystem.VisualScripting.Control
    6. {
    7.     /// <summary>
    8.     /// Branches flow by switching over an InputSO.
    9.     /// </summary>
    10.     [UnitCategory(Constants.UnitCategoryPrefix + "/Control")]
    11.     [UnitTitle("Switch On Input")]
    12.     [UnitShortTitle("Switch")]
    13.     [UnitSubtitle("On Input")]
    14.     //[UnitOrder(5)]
    15.     public class SwitchOnInputSO : SwitchUnit<InputSO>
    16.     {
    17.     }
    18. }

    Attached Files: