C++ Scripting: Part 15 – Delegates

Tags: , , , , ,

This week’s article adds another major feature to the C++ scripting system: delegates. These are vital so C++ game code can use features like Unity’s UI system (a.k.a. UGUI). Without them, we wouldn’t be able to handle button clicks or other UI events. So read on to learn how these were implemented in the GitHub project.

Read the rest of this article »

No Comments

C++ Scripting: Part 14 – Arrays

Tags: ,

The series continues by adding support for a major feature: arrays. These are used very frequently throughout the Unity and .NET APIs and the lack of support for them has been a big missing piece of the puzzle for most games. The GitHub project has been updated to support single- and multi-dimensional arrays. Read on to learn how this support was implemented!

Read the rest of this article »

No Comments

C++ Scripting: Part 13 – Operator Overloading, Indexers, and Type Conversion

Tags: , , ,

Today’s article continues the series by adding support for C++ to call the various overloaded operators and indexers that are written in C#. This includes support for all 24 overloadable operators in C# plus the explicit and implicit type conversion operators. Indexers aren’t quite overloaded operators, but they allow for array-like indexing into C# types so they’re included today. Read on to learn how all this support was implemented in the GitHub project!

Read the rest of this article »

No Comments

C++ Scripting: Part 12 – Exceptions

Tags: , ,

Like them or not, exceptions are the standard way of handling programming errors in C#. We need to be able to catch C# exceptions in our C++ code so we can gracefully recover from them. Likewise, we need uncaught C++ exceptions to behave like unhandled C# exceptions: display an error and move on instead of crashing. Today’s article continues the series by implementing both those features in the GitHub project and explaining how that implementation was done.

Read the rest of this article »

No Comments

C++ Scripting: Part 11 – Collaborators, Structs, and Enums

Tags: , ,

The series to build a viable system to write Unity scripts in C++ continues! While these 11 articles have covered a lot of ground toward making a usable C++ scripting system, there’s still a lot to do. Writing the code for these articles takes quite a lot of time, so today I’m officially calling for collaborators on the GitHub project. If you’d like to join in, please leave a comment, send an e-mail, or submit a pull request. There’s plenty to do and your help would be greatly appreciated! Aside from that, today’s article is all about adding support for struct and enum types so we can use types like Vector3 and TextureFormat from our C++ scripts.

Read the rest of this article »

No Comments

C++ Scripting: Part 10 – Full Generics Support

Tags: , , , , , , ,

C# APIs are chock-full of generics. Generic types, generic method parameters, generic return types, generic fields, generic properties, deriving from generic types, and generic constructors. We can find all of these in the Unity and .NET APIs. Some are more frequent than others, but we’re going to need support for all of them to make C++ scripting a viable alternative to C#. Today’s article continues the series by adding just that: support for all of these kinds of generics. Let’s dive into how to use them as well as some bonus items added to the project this week.

Read the rest of this article »

No Comments

C++ Scripting: Part 9 – Out and Ref Parameters

Tags: , , , ,

It’s been quite a while in the series since we’ve added any fundamental C# language features. Today we’ll address one of the limitations of the C#/C++ communication: the lack of support for out and ref parameters. This is important as they’re commonly used by both the Unity API and .NET and we’d like C++ to be able to call functions with these kinds of parameters. So let’s delve into what it means for C++ to use out and ref parameters and see how to implement support for that across the language boundary.

Read the rest of this article »

2 Comments

C++ Scripting: Part 8 – Platform-Dependent Compilation

Tags: , , , ,

The series continues today to fill a small, but important gap in the C++ plugin’s build script. Unity helpfully provides symbols like UNITY_IOS for us to check with #if. This lets us add and remove blocks of code that should only be present in a certain build of the game. We’d like the same functionality in C++ that Unity provides to C#, so today we’ll upgrade the build script to allow that.

Read the rest of this article »

No Comments

C++ Scripting: Part 7 – MonoBehaviour Messages

Tags: , , , ,

The series continues this week by addressing a pretty important issue. Previously, we were limited to doing all our work in just two C++ functions: PluginMain and PluginUpdate. This isn’t at all the normal way to work in Unity. It’d be a lot more natural to write our code in MonoBehaviour classes. So today we’ll come up with some tricks to allow us to write our MonoBehaviour code in C++ so we are truly scripting in C++.

Read the rest of this article »

No Comments

C++ Scripting: Part 6 – Building the C++ Plugin

Tags: , , , ,

Today we’ll continue the series by addressing a nagging problem: how do we build the C++ plugin? With C# we inherit, for better or worse, Unity’s build system where we just edit .cs files and press the play button. This doesn’t work with C++, so we’ll need to build something similar that’s just as easy to use.

Read the rest of this article »

No Comments