How do I check for the IL2CPP scripting backend/setting?

With my plugin, I have a couple of problems with [marshalling in] mono. These problems are okay in IL2CPP, (which is required anyway for ios now)

Can I check to make sure IL2CPP is set and throw, or print errors, or even better, compile-time errors if IL2PP is not selected?

Thanks to Dave Carlile and Graham, the king of unity support in the linked answer. (Obviously I’ll have a better error message)

		UnityEditor.ScriptingImplementation backend = (UnityEditor.ScriptingImplementation)UnityEditor.PlayerSettings.GetPropertyInt("ScriptingBackend", UnityEditor.BuildTargetGroup.iOS);
		if (backend != UnityEditor.ScriptingImplementation.IL2CPP) {
			Debug.LogError ("Warning: If the scripting backend is not IL2CPP there may be problems");

Would be interested to know if anyone has any compile-time solutions, but an error when running in the editor is good enough for now :slight_smile:

Here is a super simple way to check from the Editor code if current build settings have IL2CPP selected as a scripting backend:

public static bool IsIL2CPPEnabled()
	return PlayerSettings.GetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup) == ScriptingImplementation.IL2CPP;

Note, you can also set it in similar way, if target platform supports IL2CPP:

PlayerSettings.SetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup, ScriptingImplementation.IL2CPP);

It’s new, support new version higher then 5.6