Today we’ll go through everything that happens when you make a P/Invoke call. We’ll see how native libraries are loaded and how marshaling works. We’ll touch on calling conventions and character sets. In the end, we’ll have a better understanding of what goes on when we call into native code.
Archive for category Unity
There are many posts that’ll tell you the “hello world” of calling native code like C++ from a C# Unity project. These tend to be simple examples though, so it’s hard to go from that to wrapping a real life useful native library. Today we’ll wrap SQLite, a popular C library that implements a database, and talk about the challenges in doing so and how to end up with a pleasant C# API for the rest of the game to use. Read on to learn how!
Today’s tutorial gives step-by-step instructions on how to use F# as a programming language in Unity. It updates an older tutorial from 2015 that used Unity 5.2 because a lot has changed in Unity since then. With an improved IL2CPP and support for .NET Standard 2.0, it’s easier than ever to simply drop in F# support. Read on to learn how!
Sometimes you just want a small array without the heap allocations and GC. Existing solutions like stackalloc
require unsafe
code, don’t allow for dynamic growth, and don’t support foreach
loops. So today we’ll design and build a code generator that puts a new tool in your toolbox!
Unity’s C# job system is a powerful tool, but it can be difficult to understand how various jobs, their dependencies on each other, and the data they use all work together to accomplish a task. Today we’ll create a little tool that visualizes and generates job graphs so it’s much easier to understand them and easier to build larger, more powerful graphs.
C# makes it easy to create large graphs of objects connected by their fields. The larger this graph grows, the more complex it is to deal with objects in the graph. It’s hard to look at code or set a breakpoint in a debugger and get an intuitive sense of all these connections. So today we’ll write a small tool to visualize an object graph!
Unity 2018.3 brings us even more thread-safe APIs that we can call from the C# job system. Today we’ll look at a systematic way to find them all so we know what’s safe to use and what’s not.
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!
Continuing the series, today we’ll dive into local functions, fixed
-size buffers, fixed
blocks on arbitrary types with GetPinnableReference
, and stackalloc
initializers to see how they’re all implemented in C++ and what assembly code ends up actually running on the CPU.
Today we continue the series by looking at a pair of powerful, related features in C# 7.3: ref
return values and local variables. These enable some great optimizations, so let’s look at the IL2CPP output for them to make sure it’s as good as it looks.