While Unreal Engine doesn’t provide C# support out of the box, it does provide an exceptional plugin system, so it was only a matter of time until C# plugins arrived. Today we are looking at the open source USharp extension, which is based on the MonoUE plugin project. Using this plugin, UE4 gains C# functionality with the following features:
- Write C# using UObject exposed types (AActor, AGameMode, UActorComponent, etc). Define new UObject types and inherit existing ones. Exposed C# types can then be used in (or extended by) Blueprint.
- Access to Unreal’s reflection system (UClass, UFunction, UProperty, etc).
- Dynamically switch between .NET Framework, .NET Core and Mono for an improved debugging / runtime experience without having to reopen the editor
- Supports Windows, Mac and Linux
There are however some downsides:
- This project depends on a lot of PInvoked functions which could potentially behave differently on different C++ compilers. This project may not work on some target platforms.
- Like mono-ue this project depends on lots of generated code and IL weaving. It probably isn’t the best for performance and there is a huge amount of generated code everywhere.
- The weaved IL currently seems to break edit-and-continue debugging (issue with cecil?)
- There is currently too much marshaling on structs / collections (list, map, set). Marshaling needs to be redesigned to avoid copies of entire collections / structs on trivial calls between C# / native code. Additionally marshaling of delegates needs to be redesigned (various issues such as being referenced as a copy of the delegate).
If you are interested in checking out USharp, you can find the installation instructions here. One potential problem to be aware of, the project creator doesn’t seem to have attached a license to the code repository! While this code is not production-ready, if you intend to use it in any capacity, I would make sure the license is suitable. See the results of the plugin in action in the video below.