Today’s article guides you through the necessary steps to create, use, and debug a .NET DLL in Unity. These can help you modularize your code into libraries that can be imported as a single file by the users of your library. They’re especially useful when utilizing the “pure code” approach to code design as you can easily break up a Unity app’s monolithic structure into reusable components. So read on to learn how to use DLLs in Unity!
Archive for category Unity
One type of function was left out of Unity Function Performance: virtual functions. Functions in C# are non-virtual by default and you have to explicitly use the virtual
and override
keywords to override them. Why not make this the default, like in AS3 or Java? Are virtual functions that much slower? Today’s article finds out! Should you be worried every time you make a function virtual
?
How fast are C# delegates and events? The best answer is “compared to what?”. You probably use callbacks all the time, but what’s the fastest kind of callback? C# delegates and events are nice, built-in features of C#, but you could also implement your own callback interface. Would that gain you any speed? Read on for the performance test and results!
As you use iterator functions (and yield
) more and more, you’ll start to run into some limitations in the C# language. For instance, you can’t yield
inside a try
block that has a catch
block. And the foreach
loop doesn’t provide a very good way to catch exceptions when looping over an iterator function, either. Today’s article goes into detail to find solutions to these issues and make iterator functions usable in even the trickiest scenarios!
C# supports iterator functions with the yield
keyword. Unity uses them to support coroutines. Unfortunately, both are poorly understood by many Unity programmers. Today’s article dives into iterator functions and coroutines to better understand how they work and what they can be used for. Read on to learn how to use iterator functions and coroutines for more effective asynchronous code!
Today’s article shows a class that helps clean up your foreach
loops when you want to call Add()
or Remove()
on the List
you’re looping over. Normally you’d get an exception, but today’s class works around that problem so your code is less error-prone and easier to read. It also discusses some workarounds you can use even if you don’t use SafeList
. Read on to learn how to make your foreach
loops less error-prone! UPDATE: SafeList 2.0 is out!
Today’s article is about WebCall
, a class to make Unity’s WWW
cleaner and easier to use. How could it be cleaner or easier than it already is? By adding C# events! Normally your web calls have lots of clutter around them, your logic gets split across functions, and handling the call is hard when the GameObject
or MonoBehaviour
get destroyed. WebCall
solves all these problems so your web calls are clean, easy, and robust. Read on for the source code and examples!
What’s the fastest way to build a string
in C#? We have several options available to us. string.Format()
is a function built right in to the string
class., Concatenation ("a" + "b"
) is a feature of the language itself! The System.Text.StringBuilder
class is a built in class with a name that makes it sound like it’s purpose-built for building strings. Today I pit these three against each other to find out just which one you should be using to build strings as quickly as possible.
The new IL2CPP scripting backend in Unity 4.6.2 and 5.0 is supposed to be much faster than the old Mono backend. I ran some benchmarks, but mostly found slowdowns compared to Mono. Today’s article shows the tests I ran, the results I got, and wonders why the IL2CPP version seems so slow. Perhaps one of you, dear readers, knows the reason why. Update: Part of the reason why has been discovered. Read on for updated results.
Which is the fastest kind of C# function in Unity? There are several to choose from: regular old instance methods, static methods, delegates, and lambdas. Is there any performance reason to choose one over the other? Today’s article answers just these questions by putting each type of function to the test. Read on to see which is fastest and which is slowest!