Uninitialised Ramblings

Tom Haygarth's Programming blog

Debugging a Native iOS Unity plugin

Context

I thought I’d kick this new blog off with a little tutorial that I hope would be useful. I was working on a little native iOS plugin for Unity and needed to do a little debugging of the static library I had built for it and thought it might be a useful tutorial for someone.
Also I’m writing this to be accessible to most people programming with unity and will be making the assumption that this may be their first native library plugin. If you’re familiar with writing native libraries then you can probably skip the first step.

Tutorial

Step 1 - Build a debug version of your plugin

First thing that will need to be done is to build a debug version of the native library your plugin uses. To do this open the xcode project and select the the build target in the top left of the screen

and select the edit scheme option.

In the edit scheme window set the build configuration option to debug.

After setting the option, hit the close button and then build a new version of the library. Once the build completes replace the native library file in your Unity project with the newly built debug version and build your Unity iOS game as an Xcode project.

Step 2 - Attaching the debugger

Open up the exported Xcode project for your Unity iOS game and hit the run button to build and deploy your game to your iOS device. Once your game is running make sure the debug navigator is showing.

Note down the process or process ID (PID) of your game.

To debug your library from its Xcode project you will first need to detach the debugger from the game’s Xcode instance. To do that select the Debug -> Detach from game option from the toolbar

Next open up your Xcode project for your native library and set deployment device to your iOS device.

Once you have the device selected you can then attach your project to the debugger by selecting Debug -> Attach to Process by PID or Name.

In the dialog that opens type the name of the game process or PID that you recorded earlier and hit the Attach button.

Step 3 - Debugging

After a minute or so your debugger will attach and now you will be able to place breakpoints in Xcode and hit them whenever your unity game code calls your native plugin code.

Step 4 - Conclusion

Hopefully this tutorial is helpful to someone who might be writing a native Unity plugin for iOS. Just don’t forget to replace your debug native library with a release one when you’re planning to release your iOS game or Unity Plugin. You can do that by following Step 1 but instead setting the Build Configuration to Release instead of Debug.

Enjoy your Debugging :)

Blog Rebuild

For a while I’ve been meaning to redesign this website and keep it a little more active. The plan is to write some tutorials and updates on various projects I’m working on in my free time.

Blog site construction

So one of the projects I’ll be working on is this site in general. The previous version was constructed using a lot of PHP and a MySql database that was functional but not very optimal. I did build up a backend that allowed me to add, edit, and delete posts but that was pretty rudimentary and was a little bit clunky to maintain and add new features to. All of this resulted in a functional site but one that wasn’t overly pretty and didn’t scale for mobile platforms.

So I’ve decided to take a different approach to building the new site and create a static site using the Hexo framework and bootstrap. For the first iteration of the redesign I have adapted Jonathan Klughertz’s tutorial for creating a Hexo theme that recreates the bootstrap blog example. Hopefully this will result in a more responsive site (as the pages won’t have to be built from pulling info out of the database) and that the site will also scale better for mobile screens.