SceneKit is one of my favorite Apple iOS Frameworks. It allows for developers at all different levels to create 3D scenes and animations. When things go wrong though it can be difficult to find the cause. Here are a few tips to diagnose issues.

1. Scenekit graph Debugger

If you only take away one thing from this post let it be this. The biggest issues with scenekit is usually managing the hierarchy of SCNNode objects. Sometimes node are out of place or not showing up in the scene at all. Using this tip you can stop the app and view the scene and all the nodes in the hierarchy.

In this example I’m going to be debugging an ARKit scene where I should have two objects (candle, and coffee cup) but I only see one.

First open your problematic SceneView and make sure it is visible on the screen. And then click the Debug View Hierarchy button.

It will take a second for Xcode to capture the full view hierarchy, but when it’s finished it should look like this. As you can see, only the coffee cup is visible.

Click on the SceneView in the view hierarchy in the side panel.

Once you click on that usually your problem will become immediately clear.

In my case the coffee cup was in the right X and Y position, but the Z position was inverted putting it behind the SceneKit Camera (iPhone).

I’ve used this several times while building Panda (btw we’ll be hiring soon more here), it has helped me debug many positioning, scaling, and animation issues.

One final note, you can export the whole scene as a DAE file by pressing export button in the corner of the view. This is really useful if you are working with a 3D designer, and some of your 3D models aren’t showing up correctly. Export the scene and send it to your 3D designer and they’ll likely see the issue right away.

2. Setting Debug options on the Scene View

This one is really quick in easy. Every Sceneview has debugging properties built in and can be used to view useful information.

First you can turn on statistics reporting on a SceneView by setting it’s showStatistics to true.

sceneView.showsStatistics = true

Afterwards you’ll see a display on the bottom of the SceneView giving you the frame rate, and GPU resource usage of the view.

The other properties can be set on the SceneView are under the SCNDebugOptions. You can outline wireframes, bounding boxes and more.

sceneView.debugOptions = [.showWireframe, .showBoundingBoxes]

Wireframe on the ARKit Face Tracking Mask

ARKit has it’s own special properties you can add with ARSCNDebugOptions .

sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]

The above options will display all of the feature points ARSCNView uses to create a ARAnchor.

showFeaturePoints in action

For all the options you can set on a SCNView, and ARSCNView read Apple’s Documentation.

3. Use Quick look in Xcode

This is last one is a quick one. Often times it is easy to mix up nodes in code. This will help you see what the underlying node is. Just put a breakpoint on the node in question, and you can quickly look at what a SCNode looks like in your text editor with the Quick Look. Highlight the node and click the eye button.

What are your Xcode debugging tips?

Share your tips in the comments below or tweet them to me @gabriel__lewis

Follow me for more tips on Xcode, Swift and iOS Development