> For the complete documentation index, see [llms.txt](https://www.unrealsharp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.unrealsharp.com/getting-started-and-fundamentals/your-first-script.md).

# Your First Script

### Creating the class

Open the U# toolbar and choose **Create New C# type**. This step is not needed, you can also create types in your IDE of choice, this is simply to speed up the process of creating types.

<figure><img src="/files/KoEEzy3xp5NgyHKbTW49" alt=""><figcaption></figcaption></figure>

Now choose the name, file location and parent class. For the purpose of this tutorial I'll choose an actor class.

<figure><img src="/files/4tdGGmx0x1qlinOUeEFB" alt=""><figcaption></figcaption></figure>

### Actor Class Example

Below is an example how a actor class in U# can look like, and how it exposed functions and properties to Blueprint.

```csharp
using UnrealSharp.Attributes;
using UnrealSharp.CoreUObject;
using UnrealSharp.Engine;

namespace ManagedTestCSharp;

[UClass]
public partial class AMyTestClass : AActor
{   
    // Automatically instantiated as a component, attached to the root, and editable in the defaults
    [UProperty(DefaultComponent = true, RootComponent = true)]
    public partial UStaticMeshComponent MyStaticMeshComponent { get; set; }
    
    // Can be read from Blueprints, but only set from C#
    [UProperty(PropertyFlags.BlueprintReadOnly)]
    public partial int MyInt { get; set; }
    
    // Can be read and set from Blueprints
    [UProperty(PropertyFlags.BlueprintReadWrite)]
    public partial IList<int> MyList { get; set; }
    
    // Can be read and set from Blueprints, but only editable in the defaults, not per instance
    [UProperty(PropertyFlags.BlueprintReadWrite | PropertyFlags.EditDefaultsOnly)]
    public partial bool MyBool { get; set; }

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

    [UFunction(FunctionFlags.BlueprintCallable)]
    public void MyFunction(int myInt)
    {
        MyInt = myInt;
        PrintString($"MyInt set to {MyInt}");
    }
    
    [UFunction(FunctionFlags.BlueprintCallable)]
    public bool TraceSingleFromPlayerView(APlayerController playerController, float traceDistance, ETraceChannel traceChannel, out FHitResult hitResult)
    {
        APlayerCameraManager cameraManager = playerController.PlayerCameraManager;
        APawn pawn = playerController.ControlledPawn;
    
        FVector cameraLoc = cameraManager.CameraLocation;
        FVector cameraDir = cameraManager.CameraRotation.ToVector;
        
        double cameraToPawnDist = FVector.Distance(cameraLoc, pawn.ActorLocation);
        double totalDistance = cameraToPawnDist + traceDistance;

        FVector start = cameraLoc;
        FVector end = start + cameraDir * totalDistance;
    
        IList<AActor> ignoreActors = new List<AActor> { pawn };
        return SystemLibrary.LineTraceByChannel(start, end, traceChannel.ToTraceQuery(), false, ignoreActors, EDrawDebugTrace.None, out hitResult, true);
    }
}
```

Return to the Unreal Engine editor, and your project will automatically compile the new code, and your class will be ready to use.

<figure><img src="/files/7Ndf3jJthAUMMszeGvya" alt=""><figcaption></figcaption></figure>

Now these members can be called from Blueprints!

<figure><img src="/files/WMRScVKB4DiOV4JEDkLp" alt=""><figcaption></figcaption></figure>
