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
  • Setting a Root Component
  • Attaching More Components
  1. Documentation
  2. Classes

Default Actor Components

In Unreal Engine, actors can be composed of multiple components that represent physical parts of the object, such as meshes, cameras, or lights.

Setting a Root Component

Every actor needs a root component, which serves as the parent for all other components in the actor’s hierarchy. The root component defines the actor’s position, rotation, and scale in the world.

To define a root component using UnrealSharp, you use the [UProperty] attribute with the DefaultComponent and RootComponent flags set to true:

[UProperty(DefaultComponent = true, RootComponent = true)]
public USceneComponent MyRootComponent { get; set; }
  • DefaultComponent: This flag indicates that the property should be automatically instantiated as a component when the actor is created.

  • RootComponent: Setting this flag to true designates this component as the root component of the actor.

Attaching More Components

Once the root component is set, you can begin attaching other components. A common requirement is to attach a visual representation to your actor, like a static mesh.

To attach a component as a child of the root component, use the AttachmentComponent parameter to specify the parent component’s name:

[UProperty(DefaultComponent = true, AttachmentComponent = nameof(MyRootComponent))]
public UStaticMeshComponent MyStaticMeshComponent { get; set; }

You can also attach components to another component’s socket:

[UProperty(DefaultComponent = true, AttachmentComponent = nameof(MyRootComponent), AttachmentSocket = "MySocketName")]
public USkeletalMeshComponent MySkeletalMeshComponent { get; set; }
PreviousMetaDataNextHelper Methods

Last updated 8 months ago