Catching Exceptions in Coroutines

Tags: , ,

Unity code frequently makes use of the coroutine feature of MonoBehaviour. It can make asynchronous code a lot easier to write, but runs into problems when exceptions are thrown. There’s no avoiding exceptions since they’re built into C# (e.g. NullReferenceException) but we can cope with them, even when they’re in coroutines. Today’s article introduces a helper function or two that you can drop into your projects to help you handle exceptions thrown from your coroutines. Read on to learn how!

Read the rest of this article »

No Comments

JSON Libraries Comparison in Unity 5.5

Tags: , , , ,

Unity 5.5 has been out for about a month now and it’s time to update the benchmarks for JSON libraries. Which is fastest now? Which creates the least garbage? Read on to find out!

Read the rest of this article »

1 Comment

Unit Testing Code That Uses the Unity Engine: Part 2

Tags: , , , , ,

Last week’s article showed a technique that you can use to abstract the Unity engine so that you can test code that uses it. Today’s article presents another technique that allows you to remove this abstraction layer so your game code is faster and more natural. Read on to learn how!

Read the rest of this article »

No Comments

Unit Testing Code That Uses the Unity Engine: Part 1

Tags: , , , ,

How do you write unit tests for code that uses the Unity engine to play sounds, make web calls, or render graphics? Today’s article shows one solution!

Read the rest of this article »

No Comments

How to Detect If the Unity Engine Is Available

Tags: , ,

Sometimes we write code that’s meant to be run outside of the Unity engine. This could be anything from unit tests being run in MonoDevelop or Visual Studio to shared code that’s used on a multiplayer server. Regardless, the Unity engine isn’t available for use unless you’re running in the editor or a deployed build. This means you’ll have problems whenever you access the Unity engine via Debug.Log, GameObject, or MonoBehaviour. Today’s article shares some quick tips that enable you to tweak your code so that you can detect whether the Unity engine is available for use. Read on to learn how!

Read the rest of this article »

2 Comments

How to Easily Use Callback Functions in Coroutines

Tags: , ,

In asynchronous programming we’re constantly dealing with callback functions. Maybe you have to call some function in a third party library that takes a callback function. Regardless, Unity programmers often want to use coroutines for their asynchronous tasks. Today’s article show you how you can use callback-based code from your coroutines, all while being simple and easy to use. Read on to learn how!

Read the rest of this article »

2 Comments

Inadvertent “Global” Variables

Global variables are bad for a variety of reasons. Chief among them is that you can’t just look at one part of the code in isolation because it may be affected by a global variable that’s being used elsewhere. The problem actually exists as a spectrum where global variables are the worst and local variables are the best. In between are all kinds variables that make up the program’s “shared state”. Today’s article discusses that part and shows just how easy it is to inadvertently introduce it!

Read the rest of this article »

No Comments

Runtime Assert Levels

Logs have levels: debug, warning, error, etc. So why are all runtime asserts on just one level? Today’s article provides some code that allows you to add levels to your asserts based on how fast they are: fast, normal, slow, super slow. It also shows how to use these levels to balance between performance and safety.

Read the rest of this article »

No Comments

How to Use Runtime Asserts to Find Bugs

Tags: , , , ,

Runtime asserts, not the asserts in unit tests, are a valuable debugging tool for any game developer. Today’s article shows you what they are, how to use them, how not to use them, and how they work. Read on to learn more!

Read the rest of this article »

No Comments

Replacing Events in MV-C

Tags: , , , , ,

This article shows you how to remove events from the MV-C design pattern to make it simpler to understand, safer to use, and faster to execute. It’s a step-by-step lesson in refactoring. Start by reading the MV-C article, then read on!

Read the rest of this article »

3 Comments