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!
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!
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.
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!
There’s no question that the
for loop is a good idea, but events are much more complex. They’re enshrined into C# by the
event keyword, but not everything about them is good. Today’s article shows some considerations you should take into account when deciding whether or not to use an event. Bonus: it includes some little extension methods to make using events and delegates easier!
Last year I introduced a Unity-based model-view-controller (MVC) design pattern and in the many comments on that article, a theme arose. The “model” part of MVC is arguably not necessary since Unity stores so much of the data itself. Today’s article takes that theme and elaborates on it to create and introduce a new Unity-specific design pattern. Read on to see how this adaptation of MVC works!
By request, today’s article follows up on my Unity Function Performance article from a year and a half ago using Unity 5.0. It adds on
virtual functions to get a more complete picture of how various function calls in Unity perform. Of course it runs these tests using Unity 5.4 to see if there have been any changes in the engine. Read on for the results!
Iterator functions and their ability to
yield return values then continue on really come in handy for a variety of situations. Unfortunately, they come with some pretty serious performance and garbage creation drawbacks. So today’s article explores alternatives in various forms of callbacks: delegates, interfaces, and classes. Can they perform better than iterator functions? Can they avoid garbage creation? Read on to find out!