It was due to having auto properties on serialized classes:
public TileData TileData
{
get;
private set;
}
Using properties with [SerializableField][SerializeField]
private fields fixes it:
[SerializeField]
private TileData tileData;
public TileData TileData
{
get { return tileData; }
private set { tileData = value; }
}
Or if you are lazy, just use public members[field: SerializeField]
:
[field: SerializeField] public TileData TileData;TileData {get; private set;}
(But it's against some design principles, so obviously try not to use them.)
UPDATE:
It was still losing references,
solve it by calling
EditorUtility.SetDirty()
beforeAssetDatabase.SaveAssets()