Skip to content

Latest commit

 

History

History
111 lines (68 loc) · 3.27 KB

get-started.md

File metadata and controls

111 lines (68 loc) · 3.27 KB
title layout nav_order
Get Started
default
2

Get Started

Prerequisites

Unreal Engine 5.3+ (UnrealSharp 0.2 was developed using 5.3, so may work on earlier versions)

Install .NET 8.0 SDK

Install UnrealSharp to your project

Clone this repo and place UnrealSharp in the ProjectRootDirectory/Plugins folder (make the Plugins folder if it doesn't exist) in your Unreal Engine project.

Compiling UnrealSharp

Compile the plugin as any other Unreal Engine plugin using the IDE of your choice.

Launching UnrealSharp

Start your project and everything will be setup for you.

Once Unreal Engine has fully opened, look in the directory ProjectRootDirectory/Script there will be a C# project now, it should look like this:

ScriptFolder

But instead of ManagedCropoutUnrealSharp, it should say ManagedYourProjectName. So don't get confused :D

Start Scripting

Open the ManagedYourProjectName.sln file and create a C# class.

Make a class like this:

using UnrealSharp.Attributes;
using UnrealSharp.Engine;

namespace ManagedCropoutUnrealSharp;

//Currently UClass attribute is a must for the editor to recognize the class
[UClass]
public class AMyTestClass : AActor
{
    //Optional constructor
    protected AMyTestClass()
    {
    }

    protected override void BeginPlay()
    {
        PrintString("Hello from C#!");
        base.BeginPlay();
    }

    [UProperty(PropertyFlags.BlueprintReadOnly)]
    public int MyInt { get; set; }
    
    [UProperty(PropertyFlags.BlueprintReadOnly)]
    public float MyFloat { get; set; }
    
    [UProperty(PropertyFlags.BlueprintReadOnly)]
    public string MyString { get; set; }

    [UProperty(DefaultComponent = true, RootComponent = true)]
    public UStaticMeshComponent MyRootMesh { get; set; }
    
    [UProperty(DefaultComponent = true)]
    public UStaticMeshComponent MyOtherMesh { get; set; }
    
    [UProperty(DefaultComponent = true, AttachmentComponent = nameof(MyRootMesh))]
    public UStaticMeshComponent MyMeshAttachedToRoot { get; set; }

    [UFunction(FunctionFlags.BlueprintCallable)]
    public void MyFunction(bool myBool, int MyInt)
    {
        PrintString("Hello from MyFunction!");
    }
}

Now go back to Unreal Engine and it should compile your code and your class should be able to be found in the editor.

CreateBlueprint

Debugging

Now you can close Unreal Engine, and start the project through the C# project by pressing F5, and you will attach a debugger to the Unreal Engine instance, and you can start debugging.

Rider Steps

If you're using Rider, you need to do an additional step to be able to debug.

Click on the run configurations up in the right corner:

Debugging_01

And then choose .NET / .NET Core on the Runtime setting.

Debugging_02

Hit Apply and OK. Now you can press F5 and start scripting! 😃