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
  3. Properties

C++ Properties with Getters/Setters

UnrealSharp will attempt to pair up C++ member variables with their designated getters/setters and call these functions rather than setting the value directly in memory.

It also supports the new native Getter/Setters workflow that was implemented in 5.1.

The following C++ member:

UPROPERTY(BlueprintGetter=K2_GetRootComponent, Category="Transformation")
TObjectPtr<USceneComponent> RootComponent;

maps to this C# code, which calls K2_GetRootComponent to retrieve the value:

public UnrealSharp.Engine.USceneComponent RootComponent
{
    get
    {
        unsafe
        {
            byte* ParamsBufferAllocation = stackalloc byte[K2_GetRootComponent_ParamsSize];
            nint ParamsBuffer = (nint) ParamsBufferAllocation;
            UStructExporter.CallInitializeStruct(K2_GetRootComponent_NativeFunction, ParamsBuffer);
            
            UObjectExporter.CallInvokeNativeFunction(NativeObject, K2_GetRootComponent_NativeFunction, ParamsBuffer);
            
            UnrealSharp.Engine.USceneComponent returnValue;
            returnValue = ObjectMarshaller<UnrealSharp.Engine.USceneComponent>.FromNative(IntPtr.Add(ParamsBuffer, K2_GetRootComponent_ReturnValue_Offset), 0);
            
            return (UnrealSharp.Engine.USceneComponent)returnValue;
        }
    }
}
PreviousC++ Functions As C# PropertiesNextFunctions

Last updated 7 months ago