Posts Tagged struct

Using Managed Types In Jobs

Tags: , ,

Job structs can’t contain managed types like string, class instances, or delegates. This is currently a pain as a lot of the Unity API relies on these and so we’re forced to deal with them. Today we’ll talk about how we can use managed types in our jobs to bridge the gap.

Read the rest of this article »

1 Comment

Strongly-Typed Integers

Tags: , ,

An int can be anything: points, health, currency, time, etc. We often make mistakes using one int where another int was supposed to go. Imagine a function DoDamage(int, int). It’s not obvious what the parameters mean. Today we’ll use the C# type system to make the code much more readable and less error-prone!

Read the rest of this article »

6 Comments

Optional<T>: A Nullable<T> Alternative

Tags: , , , , ,

Today we’ll make a new type that addresses some of the deficiencies in Nullable<T>. We’ll end up with a good tool for dealing with operations that may or may not produce a result or take a parameter, even in Burst-compiled code. Read on to see how it works!

Read the rest of this article »

2 Comments

P/Invoke in Burst: No Safety Net

Tags: , ,

Calling into native code like C++ from C# is a powerful interoperability tool in Unity. As we move more and more code out of Mono and IL2CPP and into Burst, will we still have this tool available? Today we’ll find out!

Read the rest of this article »

4 Comments

Tuples in Burst

Tags: , ,

Tuples are a new feature in C# 7 and they’re backed by the ValueTuple struct, not class. Hopefully they’ll be supported by Burst, so let’s try them out!

Read the rest of this article »

3 Comments

Adding Unions to Burst

Tags: , ,

We’ve seen how to add unions to C#, but does this work with the new Burst compiler? Today we’ll put it to the test and see if it can handle some of the more advanced struct customization features in C#!

Read the rest of this article »

2 Comments

Awkward Objects

Tags: , ,

We create objects out of structs and classes all the time, but oftentimes these evolve to the point where using them is really awkward. Today we’ll learn to recognize the telltale signs of an overextended object design and how to easily fix it.

Read the rest of this article »

1 Comment

Fast Structs

Tags: , ,

Structs are great for controlling memory layout and avoiding the GC, but we can go a lot further to get even more speed out of them. Today we’ll look at a simple tweak that can dramatically speed up the code using the structs without even changing it!

Read the rest of this article »

7 Comments

BitArray32 and BitArray64

Tags: , , , ,

C# already has two bit array types, but both are lacking. BitArray is a class so it requires heap allocation and GC. BitVector32 is a struct, but it’s usage is bizzare, it’s implemented inefficiently, it’s not enumerable, and there’s no 64-bit version. Today we’ll create a new, simple type to remedy these issues and add a new tool to our toolbox!

Read the rest of this article »

6 Comments

IL2CPP Output for C# 7.3: Everything Else

Tags: , , , , ,

Today we conclude the series by looking at all the remaining features in C# 7.3 that we get access to in Unity 2018.3. Read on to learn about new kinds of structs, in parameters, new where constraints, discards, default literals, generalized async returns, and new preprocessor symbols!

Read the rest of this article »

1 Comment