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. Dismiss Notice

Serializable Class On ScriptableObject Null when using AssetBundle

Discussion in 'Scripting' started by TimonSpringlab, Mar 27, 2019.

  1. TimonSpringlab

    TimonSpringlab

    Joined:
    Apr 16, 2018
    Posts:
    4
    For modularity reasons we build our game code to a dll. The assets are build to asset bundles and we load these dynamically.

    We're having a specific issue where instances of an editor-created (serialized) non-monobehaviour C# class are lost when building to dll. The instanced are however stored on a ScriptableObject which is available in our AssetBundle.
    It seems like the instances that are defined in the inspector window and visible in the raw scriptableobject file are not being correctly instantiated in our dll build.
    Running from within the editor while using dll scripts still works, but a standalone Windows build results in null references (the instances do not exist). The class itself does exist inside the dll build, because we can print a static string from it.

    The ScriptableObject which stores the list of the SerializeAble Class (PathTile.cs)
    Code (CSharp):
    1. [CreateAssetMenu(menuName = "KnuffelGame/KnuffelPath")]
    2.     public class KnuffelPath : ScriptableObject
    3.     {
    4.         [SerializeField]
    5.         private List<PathTile> tiles;
    6.         private float cleanedPercentage;
    7.         private bool isFinalPath;
    8.  
    9.         public List<PathTile> Tiles
    10.         {
    11.             get
    12.             {
    13.                 return tiles;
    14.             }
    15.  
    16.             set
    17.             {
    18.                 tiles = value;
    19.             }
    20.         }
    21.        
    22.     }
    The Serializable Class
    Code (CSharp):
    1.  [System.Serializable]
    2.     public class PathTile
    3.     {
    4.         [System.Serializable]
    5.         public enum Direction
    6.         {
    7.             Up,
    8.             Left,
    9.             Down,
    10.             Right
    11.         }
    12.  
    13.         [SerializeField]
    14.         private Vector2 tileCords;
    15.         [SerializeField]
    16.         private Direction direction;
    17.  
    18.         public Vector2 TileCords
    19.         {
    20.             get
    21.             {
    22.                 return tileCords;
    23.             }
    24.         }
    25.         public Direction TileDirection
    26.         {
    27.             get
    28.             {
    29.                 return direction;
    30.             }
    31.         }
    32.     }
    And an image of where we create the PathTiles in the editor


    And the ScriptableObject which has this list stored in text, this ScriptableObject is referenced in the scene and also available in the build, since we can debug it.
    Code (CSharp):
    1. %YAML 1.1
    2. %TAG !u! tag:unity3d.com,2011:
    3. --- !u!114 &11400000
    4. MonoBehaviour:
    5.   m_ObjectHideFlags: 0
    6.   m_CorrespondingSourceObject: {fileID: 0}
    7.   m_PrefabInternal: {fileID: 0}
    8.   m_GameObject: {fileID: 0}
    9.   m_Enabled: 1
    10.   m_EditorHideFlags: 0
    11.   m_Script: {fileID: 11500000, guid: a4a21c2da3d5300449d25802ea791b03, type: 3}
    12.   m_Name: Path02
    13.   m_EditorClassIdentifier:
    14.   tiles:
    15.   - tileCords: {x: 1, y: 2}
    16.     direction: 3
    17.   - tileCords: {x: 1, y: 3}
    18.     direction: 3
    19.   - tileCords: {x: 1, y: 4}
    20.     direction: 3
    21.   - tileCords: {x: 2, y: 4}
    22.     direction: 2
    23.   - tileCords: {x: 3, y: 4}
    24.     direction: 2
    25.   - tileCords: {x: 4, y: 4}
    26.     direction: 2
    27.   - tileCords: {x: 4, y: 5}
    28.     direction: 3
    29.   - tileCords: {x: 4, y: 6}
    30.     direction: 3
    31.   - tileCords: {x: 4, y: 7}
    32.     direction: 3
    33.   - tileCords: {x: 4, y: 8}
    34.     direction: 0
    35.   - tileCords: {x: 3, y: 8}
    36.     direction: 0
    37.  
    But for some reason the list of Tiles does not get created, it ends up without items.
     
  2. TimonSpringlab

    TimonSpringlab

    Joined:
    Apr 16, 2018
    Posts:
    4