akauper / Addressables-AssetManager

Pre-loading, Synchronicity, and Pooling for Unity Addressables
229 stars 37 forks source link

Doesn't work with IL2CPP #3

Open foxgunner opened 4 years ago

foxgunner commented 4 years ago

Hi, I tried running the Example scene in an Android device. But I am getting the following error when I try to run it.

2020-07-31 13:23:38.420 10786 10811 Error Unity NotSupportedException: IL2CPP encountered a managed type which it cannot convert ahead-of-time. The type uses generic or array types which are nested beyond the maximum depth which can be converted.
2020-07-31 13:23:38.420 10786 10811 Error Unity   at DelegateList`1[T].CreateWithGlobalCache () [0x00000] in <00000000000000000000000000000000>:0 
2020-07-31 13:23:38.420 10786 10811 Error Unity   at UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].add_Completed (System.Action`1[T] value) [0x00000] in <00000000000000000000000000000000>:0 
2020-07-31 13:23:38.420 10786 10811 Error Unity   at ExampleUI.Awake () [0x00000] in <00000000000000000000000000000000>:0 
agittm commented 4 years ago

As stated from here that IL2CPP can only contains generic types up to 7 level.

I found out the solution by adding additional args to the PlayerSetting

Here's the editor script i used

using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;

public class Il2cppCustomFlag : IPreprocessBuildWithReport
{
    public int callbackOrder { get { return 0; } }

    public void OnPreprocessBuild(BuildReport report)
    {
#if UNITY_IOS || UNITY_ANDROID
        ScriptingImplementation backend = PlayerSettings.GetScriptingBackend(BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget));
        if (backend == ScriptingImplementation.IL2CPP)
        {
            PlayerSettings.SetAdditionalIl2CppArgs("--maximum-recursive-generic-depth=50");
        }
    }
#endif
}

It will add an additional args --maximum-recursive-generic-depth and setting its value to whatever you want. In my case i set this to 50

agittm commented 4 years ago

I added a new PR #5 regarding this issue.