TeamSirenix / odin-serializer

Fast, robust, powerful and extendible .NET serializer built for Unity
http://www.odininspector.com
Apache License 2.0
1.69k stars 193 forks source link

Is it's possible to use opensource version of Odin serializer in IL2CPP? #49

Open Syjgin opened 2 years ago

Syjgin commented 2 years ago

Hi. I was trying to use opensource version of Odin serializer (downloaded unitypackage from the site after registration), but it looks like I can not use it without Unity editor tools. Serialization is not working in IL2CPP build with the error message: No AOT serializer was pre-generated for the type 'Components.GameScene'. Please use Odin's AOT generation feature to generate an AOT dll before building, and ensure that 'Components.GameScene' is in the list of supported types after a scan. If it is not, please report an issue and add it to the list manually. Components.GameScene is declared as follows: [Serializable] public enum GameScene { Menu = 0, Flying = 1, Platform = 2 } I can not found that list in the editor: I have only "refresh assembly import settings" in the "Tools-> Odin Serializer" menu. I have to install Odin inspector to be able to edit that supported types list? I also created prebuild script to generate .dll: `#if UNITY_EDITOR using OdinSerializer.Editor; using UnityEditor.Build; using UnityEditor.Build.Reporting; using UnityEngine;

namespace Editor { public class OdinFormatterPreprocessor : IPreprocessBuildWithReport { public int callbackOrder { get; } public void OnPreprocessBuild(BuildReport report) { if (AOTSupportUtilities.ScanProjectForSerializedTypes(out var supported)) { AOTSupportUtilities.GenerateDLL(Application.dataPath + "/Plugins/", "odinAssembly", supported); } } } }

endif`

But nothing changed. I have to install Odin inspector in order to be able to use serializer with AOT, or there are some other setup is required? Can't find the appropriate documentation

pshtif commented 2 years ago

Yes it is possible but the Odin Serializer doesn't have the editor tools to do the scanning/type management for you that is only part of the Odin Inspector but it is still perfectly doable to implement your own Scanning tools using Odin Serializer methods.

In your case you can also manually add the GameScene type to the supported list explicitly for it to be included in the DLL.

But as I said it can be implemented I implemented custom editor tools for scanning and explicit type definition here: https://github.com/pshtif/Dash

Syjgin commented 2 years ago

Ok, I will check this later, but of now Binary serializer is enough