Odin fails to pick up all the required classes in AOT for WebGL build

Issue #860 new
Atahan Öztürk created an issue

When doing a WebGL build I get this in my web console:

Creating a serialization formatter for the type 'System.int[]' failed due to missing AOT support. 

 Please use Odin's AOT generation feature to generate an AOT dll before building, and MAKE SURE that all of the following types were automatically added to the supported types list after a scan (if they were not, please REPORT AN ISSUE with the details of which exact types the scan is missing and ADD THEM MANUALLY): 

System.int[] (name string: 'System.Int32[], mscorlib')

IF ALL THE TYPES ARE IN THE SUPPORT LIST AND YOU STILL GET THIS ERROR, PLEASE REPORT AN ISSUE.The exception contained the following message: 
Attempting to call method 'Sirenix.Serialization.PrimitiveArrayFormatter`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]::.ctor' for which no ahead of time (AOT) code was generated.

It seems Odin is missing A LOT of my types. Looks like the culprit is the fact that I’m using pure C# objects embedded in scriptableobjects that I’m serializing.

eg try something like:

[Serializable]
public class ModuleState {
    public int[] targets;
}

[Serializable]
public class ShipState{
    public ModuleState[] moduleStates;
}

[Serializable]
public class LevelState{
    public ShipState[] shipStates;
}

[Serializable]
public class SaveFile {
    public LevelState currentGameState;
}

And this is how I would write the file:

public void WriteFile(string path, object file) {
        Directory.CreateDirectory(Path.GetDirectoryName(path));

        var context = new SerializationContext
        {
            StringReferenceResolver = cache
        };

        var bytes = SerializationUtility.SerializeValue(file, saveFormat, context);
        File.WriteAllBytes(path,bytes);

        Debug.Log($"IO OP: file \"{file.GetType()}\" saved to \"{path}\"");
    }

I’m using this post as my scriptable object cache: https://odininspector.com/community-tools/58A/serializing-references-to-scriptable-objects-at-runtime

so far AOT missed many many different types and I’m adding them back one by one. I also wish the debug print would tell me all the types at once instead of bailing at the first failed type.

Comments (0)

  1. Log in to comment