Language: EN

csharp-unrealclr

Integrating C# in Unreal Engine with UnrealCLR

UnrealCLR is an open-source library designed to integrate C# into Unreal Engine, allowing us to use C# for scripting within the game engine instead of the traditional C++.

This tool is aimed at those who want to leverage the features of the C# language in their Unreal Engine projects, providing a robust (well, somewhat) alternative to scripting in C++.

UnrealCLR is a dynamic link library (DLL) that integrates into Unreal Engine to enable communication between the game engine and .NET code. This means we can write scripts and game logic in C#, F# or any other .NET language and execute them within Unreal Engine.

Features of UnrealCLR,

  • Integration with Unreal Engine: Allows the use of C# for scripting instead of C++, making development easier for those who prefer C#.
  • Support for the Unreal Engine API: Access to most of the engine’s functionalities, including manipulation of actors, components, and the event system.
  • Interoperability: Allows the coexistence of C# and C++ in the same project, facilitating the transition or combined use of both languages.
  • Faster development: C# can be simpler and quicker to use for certain types of development due to its syntax and features.

For more details and documentation, visit the UnrealCLR repository on GitHub and explore how this library can be integrated into your Unreal Engine projects.

Installing UnrealCLR

To start using UnrealCLR in your Unreal Engine project, follow these steps to install and configure the library:

Prerequisites

  • Unreal Engine: Make sure you have a compatible version of Unreal Engine installed (for example, UE4.25 or higher).
  • Visual Studio: You will need Visual Studio with support for C++ and .NET development.

Installation

Clone the UnrealCLR repository from GitHub:

git clone https://github.com/nxrighthere/UnrealCLR.git

Copy the contents of the cloned repository to the Plugins folder of your Unreal Engine project. Ensure that the UnrealCLR directory is directly within Plugins.

Open your Unreal Engine project in Visual Studio and compile UnrealCLR.

Finally, open the Unreal Engine project. Navigate to Edit -> Plugins and activate the UnrealCLR plugin. Restart the engine to complete the setup.

Using UnrealCLR

Once UnrealCLR is installed and configured, you can start writing scripts in C#. Here’s how to do it.

Creating Scripts in C#

Create a C# Script

In the Managed folder of your project, create a new .cs file for your script. Here’s a simple example of a C# script:

using UnrealEngine.Framework;

public class MyActor : Actor
{
    public override void BeginPlay()
    {
        base.BeginPlay();
        UE_LOG(LogTemp, Warning, "Hello from C#!");
    }

    public override void Tick(float DeltaTime)
    {
        base.Tick(DeltaTime);
        // Add update logic here
    }
}

To reflect changes in your C# code in Unreal Engine, you need to compile the code using the C# compiler.

Now return to Unreal Engine and open the content editor. In the content view, you can drag and drop your C# class as if it were a normal actor, just like you would with any other actor in C++.