UnrealSharp
  • Home
  • FAQ
  • Getting Started
    • Setup
    • Your First Script
    • Debugging
    • Packaging
  • Documentation
    • Classes
      • Properties
        • C++ Functions As C# Properties
        • C++ Properties with Getters/Setters
      • Functions
        • Flags
        • MetaData
      • Default Actor Components
      • Helper Methods
    • Structs
    • Enums
    • Interfaces
    • Delegates
    • Collections
      • TArray
      • TNativeArray
      • TSet
      • TMap
    • Multiplayer
      • Replicated Properties
      • RPCs (Remote Procedure Calls)
      • Replicated UObjects
    • Primary Data Assets
      • Loading Primary Data Assets
    • Loading Soft References
    • Trace Channels
    • Static Variables
      • FWorldStaticVar<T>
      • FGameStaticVar<T>
    • Logging
    • Async
    • Gameplay Tags
      • Gameplay Tag Container
    • Extension / Mixin Methods
    • Subsystems
    • Module Lifecycle
  • Links
    • Github Repository
    • Roadmap
    • Discord
Powered by GitBook
On this page
  • Methods Available for Actor Classes:
  • Basic Spawn
  • Spawn with Transform
  • Spawn with Collision Handling
  • Methods Available for ActorComponent Classes:
  • Retrieve Component
  • Construct New Components
  • Enabling Code Generation
  • Class Requirements
  1. Documentation
  2. Classes

Helper Methods

UnrealSharp extends Unreal Engine by providing simplified methods to spawn and manage Actor and ActorComponent objects. Below are the available methods for each class type.

Methods Available for Actor Classes:

Basic Spawn

AStaticMeshActor.Spawn(worldContextObject, MyActorClass);

Spawns an instance of the specified class.

Spawn with Transform

AStaticMeshActor.Spawn(worldContextObject, MyActorClass, GetActorTransform());

Spawns an instance of the specified class at a specific transform.

Spawn with Collision Handling

SpawnActorCollisionHandlingMethod method = SpawnActorCollisionHandlingMethod.AlwaysSpawn;
AStaticMeshActor.Spawn(worldContextObject, MyActorClass, GetActorTransform(), method, instigator, owner);

Spawns an instance of the specified class with specified collision handling, instigator, and owner.

Methods Available for ActorComponent Classes:

Retrieve Component

UStaticMeshComponent? Mesh = UStaticMeshComponent.Get(actor);

Retrieves the StaticMeshComponent of the specified actor.

Construct New Components

UStaticMeshComponent MyNewMesh = UStaticMeshComponent.Construct(owner);
USkeletalMeshComponent MyNewMesh2 = USkeletalMeshComponent.Construct(owner, manualAttachment, new Transform());
USplineMeshComponent MyNewMesh3 = USplineMeshComponent.Construct(owner, MyComponentClass, manualAttachment, new Transform());

Constructs new mesh components with specified owner, attachment settings, and transform.

Enabling Code Generation

To use the code generation for your custom classes (it’s already enabled for engine classes), update your project file (csproj) to include the source generator. Add the following lines to your csproj file:

<ItemGroup>
  <Analyzer Include="..\..\Plugins\UnrealSharp\Binaries\Managed\UnrealSharp.ExtensionSourceGenerators.dll" />
</ItemGroup>

Class Requirements

For the generated methods to be applicable, your classes must be declared as partial:

public partial class AMyActor : AActor
{
   
}

public partial class UMyComponent : UActorComponent
{

}
PreviousDefault Actor ComponentsNextStructs

Last updated 7 months ago