Three More IL2CPP Surprises

The story usually has three parts. First, find the highest CPU cost functions in a profiler. Second, look at the corresponding C++ code that IL2CPP generated from C#. Third, stop using more parts of C#. Today’s article explores some more IL2CPP output and discovers some more areas of C# that are shockingly expensive to use.

Read the rest of this article »

C++ Scripting: Part 28 – Value Types Overhaul

Value types like int, structs, and enums seem simple, but much of what we think we know about them just isn’t true. This article explores how value types actually work in C# and uses that knowledge to improve how they’re implemented in the C++ scripting system.

Read the rest of this article »

Three IL2CPP Optimizations

This week we’ll take a break from the C++ Scripting series to explore three optimizations we can make to our C# code so that IL2CPP generates faster C++ code for us. We’ll cover three areas that yield big speedups: casting, array bounds checking, and null checking.

Read the rest of this article »

C++ Scripting: Part 27 – Foreach Loops

C++ doesn’t have a foreach keyword, but it does have an equivalent in “range for loops”. Today we’ll implement support for them so we can easily loop over arrays and types implementing IEnumerable and IEnumerable<T>.

Read the rest of this article »

C++ Scripting: Part 26 – Hot Reloading

Imagine being able to modify C++ game code and have it take effect without even restarting the game. That’s the motivating idea behind today’s article. Read on to see how this works and how to use it to really speed up iteration times.

Read the rest of this article »

C++ Scripting: Part 25 – Full Type Hierarchy

So far we’ve had C++ classes that derive from other classes, but not their interfaces. Today we’ll make C++ classes implement all their interfaces to form a full type hierarchy. Along the way we’ll learn about how inheritance works in C++, specifically the esoteric form known as “virtual inheritance.”

Read the rest of this article »

2017 in Review

Today we’ll take a little holiday break from the C++ Scripting series to look back at 2017 in Unity programming.

Read the rest of this article »

C++ Scripting: Part 24 – Default Parameters

We’ve been able to call methods since the very beginning, but we’ve always had to pass all the parameters. Today we’ll add support for default parameters so you can skip them sometimes. There’s a surprising amount of detail involved with this, so read on to learn some caveats of C#, .NET, and C++.

Read the rest of this article »

C++ Scripting: Part 23 – Base Type APIs

Now that we have complete support overriding everything—methods, properties, indexers, events—that can be overridden in a base class or interface, there’s a bit of tidying up to do. In today’s article, we’ll take steps to make base types much more useful by inserting them into their proper place in the type hierarchy.

Read the rest of this article »

C++ Scripting: Part 22 – Full Base Type Support

Today we’ll complete our ability to use C++ classes to derive from C# classes and implement C# interfaces. So far we’ve been able to override methods, properties, and indexers. Today we’ll add the ability to override events and derive from classes that don’t have a default constructor.
Those are the last two pieces of the puzzle that will allow us to derive from any C# base type with a C++ class. Read on for all the details about how this works.

Read the rest of this article »