Asset Store | Documentation | Discord
Roslyn C# allows runtime loading of assemblies and C# scripts using the Roslyn compiler making it easy to add modding support or in-game programming to your project. In addition, Roslyn C# also includes code security verification that allows you to specify a number of security restrictions that loaded code must adhere to including illegal namespaces and types. This makes it much safer to load 3rd party code from unknown sources.
Features
- Compile and run C# scripts at runtime
- Leverage the latest C# language features using the Roslyn C# compiler
- Fast execution. Once compiled, external scripts will run as fast as game scripts
- Allows modding support to be added easily
- Code security validation means that unsafe code can be identified and discarded
- Code security generates a detailed report upon failure containing information about illegal types used and every usage occurrence in the external code
- Simple and easy to use API for assembly, type and instance reflection
- Support for non-concrete communication using script proxies
- Automatic type construction using correct method (AddComponent, CreateInstance, new)
- Cached member tables for quick reflection
- All scripts and example are organised into namespaces to avoid type name clashes
- Fully commented partial C# source code included
- Comprehensive .chm documentation of the API for quick and easy reference
Limitations
- Requires .Net 4.x API compatibility level
- AOT platforms such as IOS are not supported
- IL2CPP builds will fail to execute at the moment - Read on for possible solution (dotnow-interpreter).
PC, Mac and Linux platforms are supported
Demo
Includes a small programming based game where the objective is to navigate a mouse out of a maze by writing code that performs the direction decision making. The code is written in game using the UI code editor and then compiled and executed to see how it performs.
This example game demonstrates some of the compiler API’s available as well as the script communication methods that Roslyn C# offers and it is also quite a fun challenge to try and create a simple AI that can reach the end of the maze consistently. All the code for this game is included in 2 fully commented C# scripts so you can clearly understand how it works.
Need an code editor for your game?
Check out our other asset asset ‘InGame Code Editor’ which is an advanced text input field with line numbering and fully customizable syntax highlighting for C# and many other languages. Check out the asset store or forum page for more info.
Roslyn C# + dotnow IL2CPP Interpreter Setup Guide (09/2022)
There is a new setup guide available to get Roslyn C# working with dotnow interpreter to run the Roslyn C# demo game on IL2CPP platforms such as WebGL. You can find the setup guide on the github wiki. Thanks to Dustin_00 for creating this guide.
IL2CPP Update(08/2021)
Introducing the dotnow CIL interpreter that is designed to load and execute CIL bytecode at runtime on IL2CPP platforms. CIL bytecode is the language that your pure C# source code gets compiled into, and our interpreter provides a runtime environment that is able to run managed code on any platform. The interpreter is written in pure C#, hence the portability, and supports arrays, collections, generics, delegates and more. It is designed to replicate the .net runtime entirely although it does have some limitations.
dotnow is open source on github under the MIT license. Feel free to try it out in your projects to get code running on IL2CPP platforms (Note that it only works with Assembly Definition assets at the moment, and code stripping is a know issue). It is currently in active development, but is mostly feature complete as far as the runtime goes. This means that most code samples should execute just fine as is, although some code might throw up issues. We have also implemented full Roslyn C# integration to make it as easy as possible to use.
Development updates: [Update #1]( [Released] Roslyn C# - Runtime C# compiler page-4#post-6547582) - [Update #2]( [Released] Roslyn C# - Runtime C# compiler page-4#post-6890285) - [Update #3]( [Released] Roslyn C# - Runtime C# compiler page-5#post-6960836) - [Update #4 ]( [Released] Roslyn C# - Runtime C# compiler page-5#post-7055284)- [Update #5]( [Released] Roslyn C# - Runtime C# compiler page-5#post-7447127)
Android Update (02/2021)
We have created a mini guide for getting Roslyn C# to run on Android platforms. Android is still not an officially supported platform, but many users have had success following the [steps outlined here]( [Released] Roslyn C# - Runtime C# compiler page-4#post-6834782).
IL2CPP Update (11/2020)
We now have a working proof of concept WebGL demo where you can compile and execute C# source code in a game built with IL2CPP. [Read more here]( [Released] Roslyn C# - Runtime C# compiler page-4#post-6547582).
Roslyn C# and dotnow integration (IL2CPP platform support)
Check out this [guide to setup Roslyn C# and dotnow]( [Released] Roslyn C# - Runtime C# compiler page-5#post-8102249) so that the maze crawler demo and other compiled code can run on IL2CPP platforms including WebGL and Android. Many thanks to danger726 for putting this guide together
4364407–395149–UserGuide.pdf (753 KB)