Hi, I'm Henry. In 2012 I quit my job as a programmer at BioWare to spend a year making my own indie games. This blog is about what happened next...

Like Spaceteam? Want to support my work?
Join the Spaceteam Admiral's Club!

Unification is Approaching

I’ve been making a lot of progress on the Spaceteam Unity rebuild but there’s still work left to do. Here’s what it looks like running in the Editor:

I’m frustrated by how long it’s taking because I really want to be working on Blabyrinth, but I’m still confident this was the right decision. I get emails every day about the game not working on various Android devices.

I’m surprised about just how much stuff there is to rebuild. I still think of Spaceteam as a small, “simple” game but it actually grew quite a lot over the last 3 years with all the upgrades, Admiral’s Club additions, new languages, and spin-off projects.

Challenges I’ve encountered:

  • Unity’s NetworkLobbyManager reloading the scene when a connection is made. I don’t want this to happen but I haven’t been able to prevent it. When the scene is reloaded various objects get reset/recreated and I have to restore their state in such a way that it looks like nothing happened. It also causes the animation to visibly stutter.
  • Publishing an iOS project and then compiling and installing to a real device is slow enough to be very frustrating. At the moment I’m trying to fix problems that only show up on the device and the iteration cycle (change, build, compile, test, repeat) involves so much waiting that it’s very easy to get distracted doing something else.
  • Slime effect (+ wiping). This was tricky even in the original game because it involves RenderTextures and custom shaders, but I had to relearn all that stuff in Unity so it was a bit time-consuming.

More C#/Unity Gotchas:

  • SyncVar objects seem to need a default constructor, or you’ll get weird errors. My OutfitPiece class had a custom constructor and it took me a while to figure out that simple adding an empty OutfitPiece() constructor made the errors go away.
  • To make the dangling panels I naively figured that adding a Hinge Joint to the object would be enough, but I also needed to add a Box Collider (despite not needed collision) or the panel wouldn’t be affected by gravity properly.
  • If you want to Join a List you have to use ToArray() first
  • When calling a coroutine from C# you must use StartCoroutine(coroutine) or it will just silently fail! My solution: I’ve been suffixing all my coroutines with “Coroutine” and making one-line helper functions that simply wrap the call.
  • If you try to override a function but don’t include the “override” keyword sometimes it will fail silently with no warnings.
  • C# does not autoconvert Doubles to Floats. Must always add “f” at the end of floating point values. Mildly annoying.

New Plugins I’m using:

  • ZestKit and now DOTween. Many of my animations are dynamic so I needed a programmatic solution for smoothly animating between different states (“tweening”). I started with Prime31’s GoKit/ZestKit but due to lack of good documentation I ended up switching to DOTween.
  • Procedural Lightning. I wanted a good shock effect for electric malfunctions, so I found a cool library for lightning bolts. Looks great and very easy to customize.
  • QR Code Scanner/Generator for the Admiral’s Club login page. I only used a few bits of code from this library but it got me on the right track.
  • Prime31 Etcetera. For showing native iOS and Android dialog boxes.
  • TextMesh Pro. I needed a way to modify individual characters in a label (eg. for Labelling Malfunction) and TextMesh Pro seems to have a lot of features. I’m still experimenting with it.
  • More Post-Processing Effects. I’m using this for wormhole and anomaly screen distortion effects like rippling and waving.

So it’s going to be a few more weeks of work at least to get the original game done, and then I have to re-port Spaceteam to Apple TV (as a bonus Chromecast/Android TV should now be much easier). Then Spaceteam ESL and the upcoming Spaceteam FSL. Spaceteam Kids is still in the works as well.

Whew! That’s a lot of Spaceteams. I’m trying to stave off the madness by filling in the cracks with some Blabyrinth development.

Space out!

The Spaceteam Networking Post

Many people have asked about the networking in Spaceteam, so it’s about time I wrote an official blog post. However, I’m currently rebuilding the entire game including the networking layer in Unity so I’ll write about both the Old System and the New System.

I’m also sharing a link to an early version of the New System, called “CaptainsMess“, as a Unity asset package. It’s not finished yet but Wifi connections work well enough for me to finish the rest of the game.

Please check it out and help me test and improve it!

CaptainsMess on GitHub: https://github.com/hengineer/CaptainsMess

The Old System (Spaceteam versions up to 1.8.x)

I wrote the original game for iOS using Objective-C and the Cocos2d game engine. It was later ported to Android by a company called Apportable. They have a cross-compiling SDK that generates Android apps from Objective-C code so there is no easily-accessible “Android source” to share. Apportable did make some of their Bluetooth code available though, which you can find here: https://github.com/apportable/Bluetooth

On iOS I used Bonjour (also known as ZeroConf) to discover other devices, which works over Wifi and Bluetooth. I wanted to make it as easy as possible to connect (users shouldn’t need to know or care *how* the game is connecting, they just want to play together!)

I learned a lot from the BeamIt! source code and also the “WiTap” sample code from Apple.

On iOS I used the NSNetServices API but I also used a third-party library called HHServices for additional Bluetooth support. I know that Zeroconf is an open protocol so I’m guessing there are probably implementations for Android.

When you choose “Play” the devices all start off as a clients and look for an available server. If they find one they try to connect to it. If they can’t find one within 3 seconds, they start advertising themselves as a server as well. When one of the connections completes successfully (client or server) the other one is cancelled. Eventually everyone gets connected. Sometimes this leads to more than one group (eg. 2 groups of 2, instead of one group of 4), but in practice this is pretty easy to fix by some players leaving and re-joining one at a time,

Once the devices are connected I use another third-party library called CocoaAsyncSocket to send messages and exchange data between phones. Again, I’m sure there are similar libraries for Android.

Other notes:

  • Bluetooth can only support 7 connections at most (I think this is a hardware limitation).
  • iOS and Android cannot connect over Bluetooth, I believe due to system-level restrictions. I’ve personally never encountered a mobile game or app that connects iOS to Android over Bluetooth. If you know a way to do this please let me know!
  • I broadcast a specific ID that represents the type of game being played, eg. “spaceteam_W_M” means that it’s a Wifi game with Massive mode turned on. That way players can only connect with other compatible games.
  • On Android when Bluetooth mode is turned on the server and client modes interfere with each other, so instead of having just the “Play” option I had to add “Host” and “Join” so the players must choose which mode they are using. It doesn’t switch between client and server automatically like on iOS.
  • Some Android devices/OS versions just don’t support DNS multicast over Bluetooth so I disable the Bluetooth option for those devices (the switch just says “Bluetooth not supported”).
  • Some Wifi routers don’t support “multicast protocols” or have “isolation mode” turned on, which lets devices connect to the internet but not to each other (the exact terminology may be different). There’s really nothing I can do about this, other than to suggest that people check their router settings to see if this mode can be changed…
  • On iOS I support devices running iOS 5.1.1 and higher but I’ve recently been having problems connecting iOS 8 to older OS versions so I may have to stop supporting iOS 5 and iOS 6.
  • On Android we support system version 2.3 and higher but on older devices even the Wifi can be unreliable (and I display a message warning about this and encouraging the user to upgrade if possible).

The New System (Spaceteam 2.0+)

I’m trying to replicate this system in Unity using as much out-of-the-box support as I can. My first attempt uses the Unity Networking HLAPI (High-Level API) introduced in Unity 5.1, specifically the NetworkLobbyManager and NetworkDiscovery classes. Unity’s source code for the HLAPI has been a great reference and is available here: https://bitbucket.org/Unity-Technologies/networking

I have my own subclass of NetworkLobbyManager and two NetworkDiscovery objects: one to broadcast and one to search.

When you choose “Play” the discovery server starts broadcasting its information and the discovery client starts searching.

The broadcast data holds information about the server, eg:

(version) : (unique peer id) : (is the server open?) : (number of players)

When this information changes, the server has to be restarted with new broadcast data and is treated as a “new” server, so the clients get another chance to decide whether to join it.

If the client finds an open server with at least 1 other player, it tries to join.

Otherwise, if nothing appropriate is found after 3 seconds, but there are enough solitary broadcasters to create a lobby then a decision is made for one of them to start a new (open) server. It’s important that the candidate is chosen unambiguously or they would split into multiple lobbies with one occupant each.

Currently the server candidate is picked naively using the lowest peer ID but this could easily be changed to favour the “best” device by comparing processor speed or something. Seems like a good idea but I’m not sure if it really matters yet.

Once players are connected to a lobby, the library then manages ready states and a countdown timer before sending a message to start the game.

So far only Wifi is supported but I’m planning to add Bluetooth support by integrating one or more 3rd-party Bluetooth libraries such as:

If you’ve used these libraries before I’d love to hear your experiences with them.

I may have to drop down to the Low-Level Network API in order to integrate them properly.

Some issues I ran into during development:

  • The broadcast data can’t be updated while the discovery server is running, so I have to restart the server every time I want to change the info. There is a bug in the Issue Tracker about this marked as Fixed but it still doesn’t work for me.
  • If I change the length of the broadcast data when I change the information (eg. using the strings “True” and “False”, which are different lengths, instead of 0 and 1) I got some weird buffer corruption. I’m going to investigate further, but just a warning in case you play with that.
  • I’m just using a single scene for Lobby/Game/Offline/Online even though Unity supports different settings for all these states. Depending on which of these values are set, I got behaviour ranging from SyncVars not working to my NetworkDiscovery objects being destroyed. Watch out for these things if you use different scenes.

Anyway here’s the link to the first public version. Feedback and improvements are welcomed and encouraged!

CaptainsMess on GitHub: https://github.com/hengineer/CaptainsMess

Space out!


Unity Progress

I’m now fully committed to the Spaceteam rebuild.

It’s a big investment in the future of all my games and the sooner it happens the better. I’ve been wasting too much time tracking down obscure bugs which will soon become irrelevant, so I’ve stopped development on the 1.8 branch until the new version (2.0) is ready.

Sorry to everyone currently experiencing crashes, you’ll have to wait a bit longer for a fix. Thanks for your patience!

In the end I decided to go with Unity 5 and I’m really enjoying it so far.

The UI system makes it easy to scale and anchor elements so they work at different screen sizes. This was a pain to get right before and annoying to test, so the new system is a pleasure to use.

The Particle system is powerful enough that I can directly recreate most of the effects I was using. I can now use Animations for some sequences I was previously doing in code.

There are handy built-in features like Serialization and JSON parsing that I get for free.

And I love being able to easily make custom visualizers and editors that work right in the Editor.

Here are some more notes on how I’m using Unity:

Project Setup

  • I’m using C# for the CaptainsMess networking portion and Javascript for the game code. But I’m considering moving everything to C# so I can get full debugger support (I’m assuming you can’t do source-level debugging in Javascript?).
  • I use Sublime Text 3 on the Mac as my script editor, but I’m also looking at Visual Studio Code which has some nice integration features and debugger support. VSCode also works much better with C# than with Javascript.
  • I’m trying to use plugins from the Asset Store as much as I can. These are the ones that have sparked my interest so far:
    • I2 Localization. I have 12 languages to support!
    • xARM. Useful for testing multiple screen resolutions on different devices (iPhone 4, iPhone 6, iPad, Android tablet, etc)
    • Google Sheets for Unity (GSFU). Handy for getting simple data tables into the game, like level progression.
    • TexturePacker Importer. I already use TexturePacker to make sprite atlases for the Cocos2d version so I assume it will help here as well, although Unity has some built-in sprite packing so maybe I won’t need it.
    • Editor Console Pro. Search, filters, and colours for the debug console.
    • VSCode. Integration for the VSCode editor.
    • PlayMaker. I had heard good things about this tool so I wanted to check it out. I like being able to create state diagrams that not only provide a high-level view of the game logic but are also functional. I still haven’t decided whether I’ll use it in production.



  • At first I looked at the Photon framework but it turned out not to be a good fit for Spaceteam. Most of their services are online rather than local and if I want to use their Redistributable Server license it seems I’d have to pay for every 500 users, which is totally untenable for my needs.
  • My current plan is to just use the built-in Unity Networking. I don’t have to pay for it and it covers most of what I need already, so the CaptainsMess library may end up being a relatively thin wrapper around it.
  • The main classes I’m using are part of the High-Level API: NetworkManager and NetworkDiscovery
    • The NetworkManager class can start a server or client but has no discovery
    • The NetworkDiscovery class can broadcast and listen for other devices but has no server/client code
  • For the initial connection I’m also using NetworkLobbyManager and NetworkLobbyPlayer
    • These classes already track “slot” (ie. player index) and “ready” state so I don’t have to
  • The main thing I’ll have to add is the ability to search for games as a server and client at the same time. The current system only supports one NetworkManager object so I’ll have to work around this with some lower-level code.
  • This networking system seems to be quite new and I’ve encountered a few weird bugs and idiosyncrasies but they’re pretty minor so far.
  • Luckily, Unity has made the source code available which makes it much easier to debug and modify: https://bitbucket.org/Unity-Technologies/networking

General Tips

  • Remember to set “Playmode Tint” in Editor prefs so you don’t lose changes you make in Play Mode!
  • Don’t name Prefabs the same as Instances!
  • If you’re doing things with a networked Player object remember to check isLocalPlayer to avoid redundancy and confusion.
  • Changing a child object name after animating its properties breaks the connection and marks it “Missing”.
  • Reference for mixing C# and Javascript:


  • Extend data classes from System.Object if you want them to be inspectable in the Editor (add [Serializable] in C#)
  • You can’t define generics in JS, but you can use them (with dot before brackets: List. instead of List)
  • Use builtin array[] in Javascript instead of Array if you want to see the items in an inspector.

I know that a bunch of you already know Unity so maybe you can help me answer some questions that I have.

My Questions

  1. Can I rearrange folders in Assets or should all extensions/plugins live at the root level? I’d like to put packages I download from the Asset Store into a subfolder but whenever I update something it wants to import it at the root level.
  2. Any tips for using the Animation Controller system as a regular state machine with transitions triggered in code? (eg. for abstract game states like Lobby, Setup, Intermission, Playing, etc). And if I do this should I be using “Trigger” parameters or just go directly to the state with Play(“StateName”)?
  3. If I have a bunch of unique objects (eg. UI screens like Title Screen, Credits Screen, etc.) should they all exist in the scene and get Activated/Deactivated as needed? Or should they only exist as prefabs and get Spawned when needed?
  4. How do you ‘diff’ scene files in source control (I use Git) to find out what changed? I’ve found some methods for saving them as text and plugins that claim to solve the problem but it seems like it could be error-prone. What do you recommend?
  5. Is there an advantage to separating things into Scene files if your game has very little content like mine? Will it be ok to have everything in one scene?

I’m officially on holiday now but I’m looking forward to continuing the project when I get back.

Thanks for listening and Happy Holidays!