Unreal Engine Integration with .NET

This section provides comprehensive documentation on integrating Unreal Engine with .NET technologies, enabling you to leverage the power of C# and the .NET ecosystem for game development.

Getting Started

Unreal Engine's C++ core provides the foundation for game logic and engine features. However, for certain types of development, such as tooling, server-side logic, or scripting, utilizing .NET can offer significant advantages in terms of rapid development and access to a rich library ecosystem.

Prerequisites

Setting Up Your Development Environment

To begin, you'll need to configure your Unreal Engine project to recognize and utilize .NET modules. This typically involves creating a specific project structure and enabling necessary plugins.

Note: Unreal Engine's .NET support is primarily managed through the Microsoft.Unreal.NET plugin, which should be enabled in your project.

Core Concepts

Unreal Engine .NET Plugin

The official Unreal Engine .NET plugin acts as a bridge between the C++ Unreal Engine and your C# code. It exposes Unreal Engine functionalities to C# and allows your C# code to interact with the engine's systems.

Managed Game Instances

You can create managed game instances that run entirely within the .NET runtime, offering a more script-like development experience. This is particularly useful for rapid prototyping and complex game logic.

Interoperability

Understanding how to pass data and call functions between C++ and C# is crucial. The plugin provides mechanisms for this, including:

Common Use Cases

Code Examples

Creating a Simple C# Actor

using UnrealEngine.Runtime;
using UnrealEngine.Runtime.Core;

[UClass]
public class MyDotNetActor : Actor
{
    [UPoperty]
    public float Speed { get; set; } = 100.0f;

    public override void Tick(float DeltaTime)
    {
        base.Tick(DeltaTime);
        // Example: Move actor forward
        AddActorLocalOffset(Vector.Forward * Speed * DeltaTime);
    }
}

Interacting with C++ Functions

Suppose you have a C++ function in your game mode like void BroadcastGameMessage(const FString& Message);.

using UnrealEngine.Runtime;
using UnrealEngine.Runtime.Core;

// Assuming you have a reference to your GameMode
var gameMode = GEngine.GameMode;
var message = "Hello from C#!";
gameMode.CallNativeFunction("BroadcastGameMessage", message);
Tip: Always refer to the official Unreal Engine documentation for the most up-to-date API references and best practices for .NET integration.

Troubleshooting Common Issues

Further Reading