Much ado about Customize

Battlefield means soldier customization. Battlefield 4 specifically allows you to customize your loadout (or kit), your weapon accessories, and your vehicle. For reasons best called historical, the whole system was and still is extremely complex and filled with technical debt. Which is where I come in.

A large part of my work on Battlefield 4 ended up being that system, because it needed a quasi-full rewrite of the UI layer. The initial goal was to reduce technical debt and make it more data-driven, it ended up allowing us to convert it to the in-house C++ UI framework rather than using Scaleform. But this is not what we'll talk about today. No, we'll talk about funny bugs.

Quite early on, one day, we fire up the game for a quick review. And we're greeted by the soldier having a glowing light orb over his head. After a good ten minutes laughing out loud and catching a quality video capture, we start looking for an explanation. It eventually turned out to be a temporary underwater indicator. "Wait", you say, "this still makes no sense". It actually does! And the same root cause led to the screen being blurry and filled with fishes another time, but tragically I do not have a screenshot of that particular hilarious bug.

See, the Customize backdrop is a standard 3D set, built in the level editor. But it needs to exist on the level to be loaded at the same time, while being out of sight from the main events, of course. Can you see where this is going? Yes, the Customize backdrop is under the level! Which technically means it's under the water level, which was triggering underwater effects like the blinker and the fishes. The fix was to add an exclusion volume, which was luckily supported in the engine.

Another time, during a regular playtest, angry emails start coming in. "How am I supposed to fly my plane with a tank floating in front of me??!" Laughs, video capture, and search for an explanation. Luckily I had just been poking at the 3D vehicle display in Customize, so that ridiculous tank sure looked familiar. It wasn't a case of broken physics, as has happened before in Battlefield, because the tank was always in a set position in front of the player's camera. Which is exactly how the Customize vehicle was positioned.

So what was going on? The Customize vehicle is a normal game entity, spawned through the same code as anything else in the game. Which is why the flying tank had physics and could be shot down. It just needs to... not... be replicated on the server. Woops.

It turns out that two lines of code had been inverted. The first line spawned the vehicle into the world. The second line told the vehicle to stay on the client, and not be sent to the server for replication. The correct order was the opposite one, since the spawning also caused replication if the option hadn't been set. And that is how stateful code will get you every time.

A fun side effect of the bug was that you could stack Customize vehicles from several clients. And so the tankcopter was born!

Those were hands-down my best bugs during Battlefield 4's development. Not the hardest to fix or the most epic hunt for a culprit, but definitely the most amusing ones. The Battlefield 4 UX team was a pleasure to be a part of, and I'm proud of what we delivered. I couldn't have wished for a better first game job.