public void ServoUnityRegisterLogCallback(ServoUnityPluginLogCallback lcb) { logCallback = lcb; // Set or unset. if (lcb != null) { // If setting, create the callback stub prior to registering the callback on the native side. logCallbackGCH = GCHandle.Alloc(logCallback); // Does not need to be pinned, see http://stackoverflow.com/a/19866119/316487 } ServoUnityPlugin_pinvoke.servoUnityRegisterLogCallback(logCallback); if (lcb == null) { // If unsetting, free the callback stub after deregistering the callback on the native side. logCallbackGCH.Free(); } }