UnrealCSharp Documentation

website·Indexed 29 days ago

https://unrealcsharp.github.io

A C# programming plugin for Unreal Engine based on .NET 10 (CoreCLR/Mono/LeanCLR). It supports full reflection types, automatic C# code generation, and static export of data types and functions. Key features include the ability to dynamically generate UClass, UInterface, UStruct, and UEnum without blueprint carriers, as well as the ability to override BlueprintImplementableEvent and BlueprintNativeEvent logic in C#.

Tokens
8.2K
Snippets
36
Records
74
Agent score
75%

What's inside UnrealCSharp

  1. Overview of UnrealCSharp Plugin

    UnrealCSharp is a C# programming plugin for Unreal Engine based on .NET 10 (supporting CoreCLR, Mono, and LeanCLR). It allows developers to write C# code within UE, featuring automatic C# code generation and the ability to statically export data types and functions. A key feature is its dynamic class capability, enabling the direct generation of UClass, UInterface, UStruct, and UEnum without requiring Blueprint containers.

    Key capabilities include:

    • Platform Support: Windows, macOS, Linux, Android, and iOS.
    • Deployment: Supports Dedicated Servers and Pak-based hot updates.
    • Debugging: Supports Editor, Runtime, and Android device debugging.
    • Development Workflow: Supports hot reloading of C# changes in the editor, including the replacement of dynamic classes.
  2. Overview of UnrealCSharp Static Export Bindings

    UnrealCSharp provides a static export mechanism to extend accessibility beyond UE's standard reflection system. This is used when classes, variables, or functions are not supported by UE reflection or are not marked as such. Static exports also serve to optimize the efficiency of variable access and function calls.
  3. Overview of Dynamic Type Generation in UnrealCSharp

    UnrealCSharp allows the dynamic generation of UClass, UInterface, UStruct, and UEnum directly via C# without needing a Blueprint asset as a carrier. Regardless of the C# namespace used, these dynamic classes are created within the /Script/CoreUObject package to ensure serialization succeeds when referenced by other classes or placed in a scene. Dynamic type attributes (UClassAttribute, UStructAttribute, and UFunctionAttribute) inherit from OverrideAttribute, meaning variable access and function calls follow the reflection binding process.
  4. Overview of UnrealCSharp Editor components

    The UnrealCSharp Editor provides several core components for managing C# integration within Unreal Engine:

    • UnrealCSharp.Editor.CodeAnalysis: Handles code analysis tasks.
    • UnrealCSharp.Editor.SolutionGenerator: Responsible for generating the project solution.
    • UnrealCSharp.Editor.Compile: Manages the compilation of C# code.
    • UnrealCSharp.Editor.Generator: Handles full generation processes.
    • UnrealCSharp.Editor.SetActive: Provides a dynamic switch to activate or deactivate the editor functionality.
  5. UnrealCSharp Framework Architecture Overview

    The UnrealCSharp framework is composed of several core modules that handle cross-version support, code generation, compilation, and integration between C# and Unreal Engine. The architecture is divided into the following components:

    • CrossVersion: Provides support for multiple versions of Unreal Engine.
    • ThirdParty: Contains the necessary headers and libraries for CoreCLR and Mono.
    • UnrealCSharpCore: Implements common functionality shared between the Runtime and the Editor.
    • ScriptCodeGenerator: Handles the generation of C# code.
    • SourceCodeGenerator: Handles the generation of C++ code.
    • Compiler: Manages the C# compilation process.
    • UnrealCSharpEditor: Implements editor-specific functionality.
    • UnrealCSharp: Implements runtime-specific functionality.
  6. UnrealCSharp Reflection and Code Generation Capabilities

    UnrealCSharp provides full support for reflection types and automatically generates C# code. It enables the static export of various data types and functions, ensuring a flexible and efficient development workflow.
  7. Build dotnet/runtime (Mono) for Android

    To build the Mono runtime for Android (Ubuntu 24 recommended), use the build.sh script specifying the Android OS and arm64 architecture.
    # Debug build
    ./build.sh mono+libs -os android -arch arm64
    
    # Release build
    ./build.sh mono+libs -os android -arch arm64 -c release
  8. Dynamic Class Generation in UnrealCSharp

    UnrealCSharp allows for the dynamic generation of Unreal Engine types including UClass, UInterface, UStruct, and UEnum directly via C#, eliminating the need for Blueprint assets as carriers.
  9. Understand UnrealCSharp reflection and type mapping

    The UnrealCSharp plugin uses Unreal Engine's reflection system to automatically generate C# representations of classes, structs, enums, and resource types based on the plugin configuration. Complex types like UObjects and Blueprints are mapped based on UE Package concepts. For example, a C++ class like AActor with the path /Script/Engine.Actor is mapped to the C# identifier Script.Engine.Actor by removing the leading slash and replacing remaining slashes with dots.
  10. Implement function overrides in C#

    To override a function in C#, follow these steps:

    1. Create a partial class for the target class and mark the class with the Override attribute.
    2. Declare a function with the same signature as the original and mark the function with the Override attribute.

    Naming Conventions:

    • Standard Functions: Use the exact name from C++/Blueprint (e.g., Test $\rightarrow$ Test).
    • RPC Functions: Append _Implementation to the C++/Blueprint name (e.g., Server_Test $\rightarrow$ Server_Test_Implementation).
    // C++ Definition
    UCLASS()
    class UNREALCSHARPTEST_API ATestCSharpFunctionActor : public AActor
    {
        GENERATED_BODY()
    
    public:
        UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
        void SetInt32ValueFunction(int32 InInt32Value);
    
        UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
        int32 GetInt32ValueFunction() const;
    
        UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
        void OutInt32ValueFunction(int32& OutInt32Value) const;
    };
  11. Trigger C# compilation via asset changes

    When asset changes occur (including additions, deletions, modifications, or renames), the system checks if the asset type and its associated module or plugin match the settings defined in the editor configuration. If a match is found, the system creates or overwrites the corresponding C# file and triggers a C# compilation.