Super quick tip!
I’ve come up with a problem when making a generic data serialization method in which I write my data to a binary file, which is an error that only occurs on iOS because it can’t run JIT ( Just-in-time ) compilation and/or AOT ( Ahead-of-time ) compilation because it doesn’t allow runtime code generation.
There are some answers on Unity Ansers, but this forum post had the same problem as I was, and there is a fix that did it for me, that’s on Unity Answers here with a pretty good explanation.
So, yup, my solution was to add that same piece of code on the file where I am invoking the code.
1 2 3 4 5 6 7 8 9 10 11 |
void Awake( ) { #if UNITY_IOS // Forces a different code path in the BinaryFormatter that doesn't rely on run-time code generation (which would break on iOS). Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes"); #endif // ... LoadData(); } |
So just in case, I’ll leave this here for future reference. 😉