Build Automation with Unity

CucumberMan

Why automate?

We’re developing Grand Cru’s first game The Supernauts in three individual teams. Changes are coming from many directions, multiple times per hour. To make sure our game stays constantly in good shape we’re using Continuous Integration with automated builds and testing.

Often running CI for the server code is enough as all of us are working with a local Unity Editor. Still, the fastest way to detect that the whole build is in good shape is to build, deploy and, in the future, test the client automatically as well.

It’s quite easy to forget to commit new files or get frequent updates from version control, making the local version work perfectly while everyone else’s environments break. If the server build itself fails the old server version keeps running and all our developers get a build failure notification into our Flowdock Team Inbox. With our CI, when things break badly, they tend to break badly for everyone and that makes sure the problems are always also fixed very promptly.

Jenkins & Amazon

Our build grid is set up with Jenkins on Amazon EC2 servers. We have a master instance running on Linux and one Windows slave to execute the Unity client builds, as there’s no Linux build support for Unity at least yet. Setting up a Jenkins slave was easier than we could’ve imagined, in fact it was so easy I’m not going to cover it here in more detail.

The build flow works so that on every commit to version control a server build is triggered. This covers also all of the C# code we’re sharing between the client and the server. Once this build succeeds, the Unity build script kicks in and after succeeding, pushes the Web Player binaries to Amazon S3 to be used with our in-house “alpha” game site together with the newly built and deployed server.

Build Scripts

Jenkins takes care of a lot of the groundwork, including version control updates, cleaning up the workspace when necessary etc. To build the Web Player binaries on a Windows Server machine, we need to execute Unity in batch mode. The tricky part was to detect any errors in the build as even if the build fails, the Unity executable returns successfully. Here’s a rough outline of the Windows build script:

set UNITY_BUILD_TARGET=..\supernauts 
Unity.exe -quit -batchmode -nographics -executeMethod BuildScript.BuildWebPlayer -projectPath [full project path] 
:: Print out logs so Jenkins can directly show what has happened in the build 
type C:\Users\Administrator\AppData\Local\Unity\Editor\Editor.log 
:: "Fool-proof" error detection, if the binary is missing the build has failed 
IF NOT EXIST ..\supernauts\supernauts.unity3d GOTO FAIL 
s3 put sww-content/UnityBuild/ supernauts.unity3d /nogui 
GOTO END 
:FAIL 
echo Build failed 
exit /B 1
:END

Another thing you’ll need to be able to execute builds on command line is a Unity build script. Ours looks like this:

using UnityEditor;
using System;
class BuildScript
{
    static void BuildWebPlayer ()
    {
        string buildTarget = System.Environment.GetEnvironmentVariable("UNITY_BUILD_TARGET");
        if (buildTarget == null || buildTarget.Length == 0) {
            throw new Exception("UNITY_BUILD_TARGET -system property not defined, aborting.");
        }
        string[] scenes = { "Assets/Level0.unity", "Assets/Level1.unity", "Assets/Level2.unity", "Assets/Level3.unity" };
        string error = BuildPipeline.BuildPlayer(scenes, buildTarget, BuildTarget.WebPlayerStreamed, BuildOptions.None);
        if (error != null && error.Length > 0) {
            throw new Exception("Build failed: " + error);
        }
    }
}

Future improvements

In the future, we’ll cover on this blog our automated testing systems. It would also be interesting to see how we can produce automated builds for mobile platforms and possibly even push them all the way to the beta users with TestFlight or similar.

On the Top of Helsinki

GrandViewHesari

Summer is upon us! Most of Finland has escaped the hustle and bustle of the city to their lakeside cottages, gone fishing or maybe bought a flight ticket to some exotic getaway. It’s the height of the vacation season at Grand Cru as well. However, those of us who are (back) at the office can always enjoy the summer at our awesome rooftop terrace! Besides the amazing view, the terrace is a perfect place for office lunches, having a coffee break, casual get-togethers and barbeque parties. Quite a Grand scenery, right?

The Cru’s hideout is found in Kallio, an urban up-and-coming district in Helsinki, where bohemian lifestyle is mainstream and where you can find the most bars per capita in Finland. Our office is located on the 12th floor of a 1960’s tower building, which looks quite grey and dreary from outside but when you step out of the elevator to the penthouse office it feels like a whole another world. As we have almost the entire floor to ourselves, it’s possible to see 360 degrees over Helsinki and as far as to the Baltic Sea.

The rooftop view in the photo is to the infamous Helsinginkatu, the main street in Kallio, occupied by hipsters and hobos. Known also by the nickname Hesari, the street has authentic working class character with cheap bars one after other. If you want to find the hip and cool places, then you have to wander off Helsinginkatu and go deeper in to the streets of Kallio.

Have an excellent weekend! Let’s enjoy the summer in the city, in Kallio or where ever you like.

p.s. I’ll tell you more about our life on the rooftop in later posts! Stay tuned.

Building the Bigger Picture

board_character

In Finland, we have this saying that well planned is half-done. Also the Cru considers flexible planning as an important part of the work, and for us it’s not just about the plan itself, it’s about the act of planning and forming the bigger picture. That’s why we’re Super excited about the large wall board we’ve created for visualizing and designing the in-game level progression. So, here’s a little sneak peek to our mischievous plans…

Our debut title The Supernauts will be based on building, as well as collecting and producing different materials. In short, the level progression will give access to new types of materials as the player advances in the game. In order to get all the elements and mechanics in balance, Grand Cru’s development team has created the visualization chart to make the planning more efficient, explicit and, also a bit fun – why not?

As you’ve probably already noticed, it looks very similar to a scrum board. However, we use it as an analysing and planning tool to improve the designing of level progression, achievements, new material unlocks, crafting system and in-game economics.

Symbol cards, post-its and color codes make the visualization very easy and the plan can quickly be adjusted to new changes. For example, each symbol card represents an individual building material, so by moving the cards we can try out new ideas and immediatly see what kind of effect the change would have on the system.

As you can see, the visualization works extremely well. The colorful board is located in a collaborative space, so each of us can easily keep track of what’s new and what has changed. What’s most important, the board gives an insight to how the system will work in the bigger picture. Needless to say, this is a work in progress, but the board has already proven to be a useful tool for development of The Supernauts!

What a Day for a First B-day

underthebridge

From the city to the woods and back. That’s what Grand Cru’s first birthday was about in the end of May. We prepared ourselves for the coming challenge by having a tasty lunch at the cafe Galleria Keidas and enjoying baked goods prepared by Good Pie Bakery. Then it was time to head to the Nuuksio National Park, and put the office workers’ ability to navigate in nature to test.

After dividing us into small teams, our guide Seppo sent us to a treasure hunt. With the help of GPS navigation and riddles hidden in the forest, each team successfully found its way to the final waypoint. As the last challenge, the teams had to solve one more puzzle to open the right treasure chest. The classic Omar candies were our sweet reward.

Mission accomplished! After rediscovering a connection with nature, we returned to Helsinki. Following the Grand Cru tradition, we celebrated with some bubbly under a bridge. To be honest, we’ve done this only once before, but maybe it’s allowed to call it a tradition after the second time. Proper Helsinkians can surely recognize our secret spot?

Hey Cru, Say Cheese!

The_Cru_May2012_photo

A couple of weeks ago, the Cru gathered for a team photo on our rooftop terrace. Sunshine, blue sky, some wispy clouds. It seemed like a perfect day for a photo shoot. Time to pose then! We had the beautiful Baltic Sea on our left side and a view to the good old Kallio district on the right.

Well, we faced a bit of a challenge. Could the old saying be true: is one picture worth a thousand words? In reality, the strong north wind messed up our hair and could probably have blown in Mary Poppins herself. Despite the freezing breeze we did our very best to make it look like a warm summer day!

Many thanks for the cool (in every meaning of the word) photo goes to the lovely and talented photographer Jenni Häyrinen.

If you want to see the other version of the team photo, go to Idga’s website. There we are posing with a silver award from the former President of Finland Tarja Halonen. She rewarded the Finnish game cluster for a job well done with internationalization.