Extension / Mixin Methods
C++ Extension Methods for C#
Extension methods are static methods that can be invoked on an existing class as if they were instance methods of that class. This is particularly useful when you want to add methods to existing classes (such as Actor
) without modifying their original source code.
Usage Requirements
To generate extension methods from C++ to C#, a C++ function needs to follow these:
Static and Public: Extension methods must be declared as
static
andpublic
in your C++ class.Meta Attribute: Use the
meta=(ExtensionMethod)
Parameter Requirements: The first parameter must be the type you are extending (
AActor*
in the case of extendingAActor
).BlueprintCallable or ScriptMethod: Ensure the method is marked with
BlueprintCallable
orScriptMethod
depending on your use case.BlueprintFunctionLibrary Needs to be in a BlueprintFunctionLibrary.
Example
And it’ll generate the following:
And can be used like this:
Last updated