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
  1. Documentation
  2. Classes

Properties

Exposing C# members to Unreal Engine, they must be marked with the [UProperty] attribute and be defined as properties.

Getters and Setters currently cannot be used as the weaver injects into them.

[UClass]
public class AMyShowcaseClass : AActor
{
    [UProperty(DefaultComponent = true, RootComponent = true)]
    public UStaticMeshComponent MyMesh { get; set; }
 
    [UProperty(PropertyFlags.EditAnywhere | PropertyFlags.BlueprintReadWrite)]
    public TMap<int, string> MyMap { get; set; }

    [UProperty(PropertyFlags.EditAnywhere | PropertyFlags.BlueprintReadWrite)]
    public TWeakObjectPtr<AMyShowcaseClass> MyWeakObject { get; set; }

    protected override void BeginPlay()
    {
        base.BeginPlay();

        PrintString("BeginPlay called!");

        MyMap.Add(1, "First Value");
        MyMap.Add(2, "Second Value");

        MyWeakObject = this;

        UpdateMapWithKey(2, "Updated Second Value");
    }    
}
PreviousClassesNextC++ Functions As C# Properties

Last updated 8 months ago