title | layout |
---|---|
Helper Methods |
default |
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.
AStaticMeshActor.Spawn(worldContextObject, MyActorClass);
Spawns an instance of the specified class.
AStaticMeshActor.Spawn(worldContextObject, MyActorClass, GetActorTransform());
Spawns an instance of the specified class at a specific transform.
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.
UStaticMeshComponent? Mesh = UStaticMeshComponent.Get(actor);
Retrieves the StaticMeshComponent of the specified actor.
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.
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>
For the generated methods to be applicable, your classes must be declared as partial:
public partial class AMyActor : AActor
{
}
public partial class UMyComponent : UActorComponent
{
}