A selection of fantastic anecdotes about Continuous Integration in Unity – Lightmaps are big! – Maintainer



A selection of fantastic anecdotes about Continuous Integration in Unity – Lightmaps are big! – Maintainer

0 0


guildford-uug-talk-ci-anecdotes

My talk for the Guildford Unity User Group 2016, "A selection of fantastic anecdotes about Continuous Integration in Unity"

On Github hymerman / guildford-uug-talk-ci-anecdotes

A selection of fantastic anecdotes about Continuous Integration in Unity

Ben Hymers http://www.benhymers.com

... here to talk about Continuous Integration in Unity

CI is a dry topic so instead of presenting as a walkthrough, I thought it'd be interesting to rattle off a bunch of anecdotes and hopefully you'll find some of them interesting!

It's a broad area, and there's likely a very wide spread of experience with it in the room so I'll give a quick intro then proceed to the meat

Hello!

I'm Ben!

  • Rare - Kinect Sports 1&2
  • Creative Assembly - Alien: Isolation
  • Lionhead - Incubation ... *cough*
  • Playsport - Motorsport Manager
  • ... and something else soon

Not a build engineer...

Quick bit of background on myself...

Advance after Lionhead

Starting new studio in Guildford soon

Something I want to point out... I'm a gameplay engineer, not a build engineer

None of this is overkill, all stuff I've seen a need for to help me do my job

Continuous Integration

Continuous Integration - What?

  • "Build automation"
  • Check project builds successfully
  • Run tests
  • Deploy

By CI I really mean 'build automation', a machine or group of machines set up to build your project automatically

Continuous Integration - Why?

  • Make sure build always works outside editor
  • Do repetetive bits devs will miss
  • Monitor project quality

I bet you've all gone to make a standalone build and found it doesn't work... nice to have the build machine catching these issues early

As your project grows... extra tasks like running tests, stripping objects from scenes... devs can't be expected to do these all the time

Easy to set up monitoring for quality issues, to notice both gradual changes over time, and sudden spikes

Continuous Integration - How?

  • Use TeamCity
  • ... or Jenkins if you don't like nice things
  • Run on normal PC, as service on Windows, PostgreSQL DB

Trust me, I've tried a bunch, TeamCity is the best

Jenkins is widely used but I found it very fiddly and not good for reporting

Anecdotes!

Lightmaps are big!

Set up script to track built game size as Team City metric

Noticed this one day after wondering about build size limits

Checked contributing changelist... lightmaps!

Bit of foresight, set up PowerShell script to track built game size, noticed spikes... lightmaps!

Lightmaps are big!

Carried on tracking this... it's not looking good!

Nearly always lightmaps

Sadly no good analysis tools - best ones are for hackers!

Maybe a bad example...

Unity build time jump

Noticed this whilst browsing standalone build duration graphs one day...

That was the day we upgraded to Unity 5.3.0!

Would maybe have noticed some time later...

Another random find, have carried on checking it though - Unity 5.3.0 came with a 33% increase in build time! Wouldn't have known the case without my trusty graphs.

Appears to be fixed as of 5.3.4

Wall-t

Nobody cares about build failures... unless they can see them!

People don't care about the build machine, and ignore emails. They don't ignore red screens!

Unity build runner plugin is fairly terrible

Didn't really work, not flexible, so I forked it. Use my fork, or use the command line and be careful with log files and how you find Unity.

Fail on log errors and artifact size change

Team City default fail conditions don't work for Unity plugin:

  • Set built-in option "an error message is logged by build runner"
  • Fail if artifact size changes by -90% or +50%
  • Catches anything that doesn't set some fail state

Write a build script!

Unity command line options are limited

  • Write your own build script (just a static method)
  • Run it with -executeMethod
  • Parse command line yourself with System.Environment.GetCommandLineArgs

Unity's command line doesn't allow you to do much.

You can parse the command line yourself to allow you to set defines, pick options more precisely etc.

Maintainer

  • Missing prefabs
  • Warning spam about missing scripts
  • Maintainer helps! Run it from the build script
  • Log stats with: ##teamcity[buildStatisticValue key='{0}' value='{1}']

Warnings as errors

Build warnings creep up over time

  • Fix them all then set warnings as errors
  • Create gmcs.rsp and smcs.rsp in Assets
  • Fill them with "-warnaserror+ -nowarn:0649"
That warning is "field is never assigned to" which happens all the time with Unity, since it does magical things with reflection

Unity bug with new/deleted files

  • Random false build failures
  • Unity compiles before updating assets! (bug 703290) (update: fixed in 5.3.5!)
  • Workaround: build twice
  • Ignore errors in first build with "Errors as Warnings" flag

Meta files

OH MY GOD META FILES

  • Check in your damn meta files!
  • Not a Unity 'Quirk' - can cause broken prefabs, materials, you name it
  • Not yet solved but considering TeamCity SWABRA plugin
  • Can report files generated by build machine
  • More than a bit flaky though!

Upgrade Unity on all machines at once

Minor updates (and patches!) change serialisation format

Devs on different versions churn files

Update all at once

Run script to force save assets

EditorUtility.SetDirty and AssetDatabase.SaveAssets

SVN is SLOW

Nightly clean build grew to ~12 hours!

Import SVN to git using git-svn and host locally

Massively faster full sync

Many problems so not rolled out yet

Copy Steampipe out of build directory

Automated Steam building is ace!

... except when it fails to log in because of Steam Guard

Turns out auth is stored locally

Copy steamcmd.exe elsewhere so auth doesn't get cleared

Unit Tests

Unfamiliar codebase - test assumptions!

Use 'Editor Tests Runner' window in-editor

Run on command line with:

  • -runEditorTests
  • -editorTestsResultFile path.xml
  • -editorTestsFilter
  • -editorTestsVerboseLog teamcity
  • "XML report processing" build feature

Future work

  • Capture all non-code warnings
  • Asset size breakdown
  • Functional testing
  • Loads more! This stuff is cool, right?!

Questions?

THE END

https://github.com/hymerman/guildford-uug-talk-ci-anecdotes

I'm hiring!

So are Playsport!

A selection of fantastic anecdotes about Continuous Integration in Unity Ben Hymers http://www.benhymers.com ... here to talk about Continuous Integration in Unity CI is a dry topic so instead of presenting as a walkthrough, I thought it'd be interesting to rattle off a bunch of anecdotes and hopefully you'll find some of them interesting! It's a broad area, and there's likely a very wide spread of experience with it in the room so I'll give a quick intro then proceed to the meat