> 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

Making your first basic script in UnrealSharp

### 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="https://4179970252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fb0wzkekwYXS1rYy7c988%2Fuploads%2Fbm2ewLPwrGCjeG5hyVlj%2Fimage.png?alt=media&amp;token=b178a4b0-4506-4ddc-b8a4-d0383cbf34b1" 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="https://4179970252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fb0wzkekwYXS1rYy7c988%2Fuploads%2FiQMAevY5XfDpT9f8ULre%2Fimage.png?alt=media&amp;token=f10047b7-4205-43ac-94b0-dc85408f1692" 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="https://4179970252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fb0wzkekwYXS1rYy7c988%2Fuploads%2Fgit-blob-23d656e5c0f6b9b7f26bccb36c738ce7ac3c4d74%2Funreal_class_wizard.png?alt=media" alt=""><figcaption></figcaption></figure>

Now these members can be called from Blueprints!

<figure><img src="https://4179970252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fb0wzkekwYXS1rYy7c988%2Fuploads%2FfrPWwkJVEMtcSd02bqxR%2Fimage.png?alt=media&amp;token=adbd4858-33a6-4259-b0a0-2123f4a2ae0f" alt=""><figcaption></figcaption></figure>
