For modularity reasons we build our game code to a dll. The assets are build to asset bundles from scene 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)
[CreateAssetMenu(menuName = "KnuffelGame/KnuffelPath")]
public class KnuffelPath : ScriptableObject
{
[SerializeField]
private List<PathTile> tiles;
private float cleanedPercentage;
private bool isFinalPath;
public List<PathTile> Tiles
{
get
{
return tiles;
}
set
{
tiles = value;
}
}
}
The Serializable Class
[System.Serializable]
public class PathTile
{
[System.Serializable]
public enum Direction
{
Up,
Left,
Down,
Right
}
[SerializeField]
private Vector2 tileCords;
[SerializeField]
private Direction direction;
public Vector2 TileCords
{
get
{
return tileCords;
}
}
public Direction TileDirection
{
get
{
return direction;
}
}
}
And an image of where we create the PathTiles in the editor
Below is the saved 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. This is the ScriptableObject that is visible in the image above.
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a4a21c2da3d5300449d25802ea791b03, type: 3}
m_Name: Path02
m_EditorClassIdentifier:
tiles:
- tileCords: {x: 1, y: 2}
direction: 3
- tileCords: {x: 1, y: 3}
direction: 3
- tileCords: {x: 1, y: 4}
direction: 3
- tileCords: {x: 2, y: 4}
direction: 2
- tileCords: {x: 3, y: 4}
direction: 2
- tileCords: {x: 4, y: 4}
direction: 2
- tileCords: {x: 4, y: 5}
direction: 3
- tileCords: {x: 4, y: 6}
direction: 3
- tileCords: {x: 4, y: 7}
direction: 3
- tileCords: {x: 4, y: 8}
direction: 0
- tileCords: {x: 3, y: 8}
direction: 0
But for some reason the list of Tiles does not get created, it ends up without items.
We tried building the scriptableobjects to a non-streamed AssetBundle and load these separately but faced the same problem.