Resolving common IL2CPP errors when testing Unity games with GameDriver

Learn how to troubleshoot common IL2CPP build errors when working with GameDriver

Several issues can occur with IL2CPP builds, resulting in inputs not being recognized or even exceptions being thrown like those below.

In the Player.log or device log:

2023-05-25 15:16:12.315 5024-5051/com.GameDriver.MobileTennis W/Unity: Unable to resolve function UnityEngine.Input::GetKey
2023-05-25 15:16:12.315 5024-5051/com.GameDriver.MobileTennis W/Unity: Unable to resolve function UnityEngine.Input::GetKeyDown
2023-05-25 15:16:12.315 5024-5051/com.GameDriver.MobileTennis W/Unity: Unable to resolve function UnityEngine.Input::GetKeyUp

This is commonly found with Legacy XR input handling (pre-Input System package):

Unable to resolve function UnityEngine.Input::GetButtonDown
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogWarning(Object)
gdio.unity_agent.ByteUtilities:GetFunctionPointer(MethodInfo)
gdio.unity_agent.GDIOAgent:Initialize()
gdio.unity_agent.GDIOAgent:Awake()

Or something indicating "Cannot marshal type..." such as the following:

MarshalDirectiveException: Cannot marshal type 'System.Collections.Generic.List`1<UnityEngine.XR.XRNodeState>'.
at OVRNodeStateProperties.ValidateProperty (UnityEngine.XR.XRNode nodeType, UnityEngine.XR.XRNodeState& requestedNodeState) [0x00000] in <00000000000000000000000000000000>:0
at OVRNodeStateProperties.GetNodeStatePropertyVector3 (UnityEngine.XR.XRNode nodeType, NodeStatePropertyType propertyType, OVRPlugin+Node ovrpNodeType, OVRPlugin+Step stepType, UnityEngine.Vector3& retVec) [0x00000] in <00000000000000000000000000000000>:0
at OVRInput.GetLocalControllerPosition (OVRInput+Controller controllerType) [0x00000] in <00000000000000000000000000000000>:0
at OVRCameraRig.UpdateAnchors (System.Boolean updateEyeAnchors, System.Boolean updateHandAnchors) [0x00000] in <00000000000000000000000000000000>:0

To resolve many issues such as these, it is necessary to run the IL2CPP Post Processor found in the GameDriver > Experimental menu in the Unity editor, and build the project again. Be sure not to run a "Clean build" after selecting this option.

You should see something similar in the editor log if the Post Processor was successful:

Once you run the IL2CPP Post Processor and build the project again, these errors should be resolved. If you still experience any of these issues, please let us know at support@gamedriver.io

"Unable to find method" errors

You may also encounter an error when calling a UnityEngine method, such as the UnityEngine.Transform method "LookAt":

api.CallMethod("//*[@name='LeftHand']/fn:component('UnityEngine.Transform')", "LookAt", new Vector3[] { target });

This can fail with the error:

Unable to find method: LookAt in object: //*[@name='LeftHand']/fn:component('UnityEngine.Transform')
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
gdio_unity_agent.MessageHandlers.Cmd_CallMethod:Process(GDIOAgent, ProtocolMessage)
System.Reflection.MemberFilter:Invoke(MemberInfo, Object)
gdio.unity_agent.GDIOAgent:ProcessEvents2()
gdio.unity_agent.GDIOAgent:UpdateRecorder()
gdio.unity_agent.GDIOAgent:Update()

This may happen even if the method seems like something that should be included in the build by default. However, this results from the IL2CPP compiler stripping out any code not explicitly used.

To work around this issue, you can simply add a call to the specific command signature to the GDIO/IL2CPP/GDIOStub.cs file prior to compilation. For example, the line below will address the error above.

(new GameObject()).transform.LookAt(new Vector3(0,0,0));

If you need to include additional methods or an entire class, you would add an entry for that class to the /GDIO/Resources/link.xml file. In this example, we would add the UnityEngine.Transform class as follows:

<assembly fullname="UnityEngine.CoreModule">
<type fullname="UnityEngine.Transform" preserve="all" />
</assembly>

A similar approach can be used for any "Unable to find method" error where the method call has been verified to work in the Editor and Mono builds.