I'm trying to compile C# code at runtime in Unity3D for IL2CPP build 64 bit Android.
I have a string of code that I want to compile and execute dynamically. The things that I've tried are:
- https://github.com/aeroson/mcs-ICodeCompiler
- https://github.com/SoapCode/UCompile/tree/master/Assets/UCompile
- https://assetstore.unity.com/packages/tools/integration/roslyn-c-runtime-compiler-142753#reviews
But what I got to understand is that all of the above doesn't work with IL2Cpp builds.
The below code is carried out using: Second Github repo mentioned above.
CSScriptEngine engine = new CSScriptEngine();
engine.AddUsings("using UnityEngine; using System; using System.Collections.Generic;");
engine.AddOnCompilationFailedHandler(OnCompilationFail);
IScript result = engine.CompileCode(@codeToConvert);
With second plugin:
AndroidPlayer(ADB@127.0.0.1:34999) ArgumentException: Invalid path
at System.IO.Path.GetDirectoryName (System.String path) [0x00000] in <00000000000000000000000000000000>:0
at Mono.CSharp.DynamicLoader..ctor (Mono.CSharp.ReflectionImporter importer, Mono.CSharp.CompilerContext compiler) [0x00000] in <00000000000000000000000000000000>:0
at Mono.CSharp.Evaluator.Init () [0x00000] in <00000000000000000000000000000000>:0
at Mono.CSharp.Evaluator.Compile (System.String input, Mono.CSharp.CompiledMethod& compiled) [0x00000] in <00000000000000000000000000000000>:0
at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set) [0x00000] in <00000000000000000000000000000000>:0
at Mono.CSharp.Evaluator.Run (System.String statement) [0x00000] in <00000000000000000000000000000000>:0
at UCompile.MonoEvaluator.Run (System.String scriptText) [0x00000] in <00000000000000000000000000000000>:0
at UCompile.CompilationUnit.Run (System.String code) [0x00000] in <00000000000000000000000000000000>:0
at UCompile.CSScriptEngine.AddUsings (System.String usings) [0x00000] in <00000000000000000000000000000000>:0
at CheckVersion.Operation_completed (UnityEngine.AsyncOperation obj) [0x00000] in <00000000000000000000000000000000>:0
at System.Action`1[T].Invoke (T obj) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.AsyncOperation.InvokeCompletionEvent () [0x00000] in <00000000000000000000000000000000>:0