UProperty
A UProperty is a special kind of UField which contains a ref to some value of an object. Also, it helps to construct and destruct that value.
Get the value reference
Getting some value reference through a UProperty is
pretty straight forward. First you need to get the
UProperty of the corresponding UClass your UObject
uses, then you just need to call the getValue
method and provide the
object (context) itself so the UProperty know from
where it should extract the value from.
UObject* obj;
UProperty* prop;
ValueType* val = prop->getValue<ValueType>(obj);
As you can see, you need to give the function the c value type cause it casts the value for you directly. To get the final value just dereference it. You're also able to set the value by just using the c reference.
If the value stored in the instance is a pointer, you need to use as
ValueType a pointer. f.e. a |
Building
The BPI provides the SML::Paks::PropertyBuilder
-Class in
assets/BPInterface.h
to make declaring and defining a custom
UProperty easier. This class has multiple types of
static initializer function for different types of
UPropertys <UProperty>.
-
- attrib
-
This function initializes a PropertyBuilder for an attribute
-
- param
-
This function initializes a PropertyBuilder for the use as an input parameter for a UFunction
-
- outParam
-
This function initializes a PropertyBuilder for the use as an output parameter for a UFunction
To get an Returnvalue-Property for a UFunction, add the
|
When you call one of this function you need to pass the property-type and the name of the property.
Flags
The builder class provides the addFlag and removeFlag methods for manipulating the property flag register.
Class-Type
Some types like Object need a UClass to know which UObjects are allowed
in that reference. For this purpose, there is the classFunc
method
which wants a function pointer to a function which returns the wanted
UClass.
You can use the provided "StaticClass" function of default UObject -types for this. |
Booleans
Booleans are tricky. They need a so-called bit-set-function. To make
this easier the PropertyBuilder-Class provides the bool
function.
This function has a template which needs to be a C++ "pointer-to-member"
which points to the attribute in your native class.
class UTestObj {
bool isSomething;
}
getPropBuilderRef().bool<&UTestObj::isSomething>()
Offset
Some properties need the offset of the value location to the
object-base-pointer like generic ones (f.e. int and Object). With the
off
function you can set that offset, but if you don’t set that
value then the other builder classes set that offset automatically. They
will look for the last given properties offset, add the used byte count
onto the offset and then use that one as the new one.
Examples
class UTestClass {
bool firstProp;
float nonProp;
int seccondProp;
AActor* thirdProp;
}
struct FuncParams {
int input;
FString output;
bool returnVal;
}
PropertyBuilder::attrib(EPropertyClass::Bool, "FirstProp").bool<&UTetsClass::firstProp>();
PropertyBuilder::attrib(EPropertyClass::Int, "WierdName").off(sizeof(bool)+sizeof(float));
PropertyBuilder::attrib(EPropertyClass::Object, "ThirdProp").classFunc(&AActor::StaticClass);
PropertyBuilder::param(EPropertyClass::Int, "input");
PropertyBuilder::outParam(EPropertyClass::Str, "output");
PropertyBuilder::outParam(EPropertyClass::bool, "retVal").addFlag(EPropertyFlag::Prop_ReturnVal);
Finishing
To finish the build you just need to execute the build
function
which returns a pointer to the proper description structure. This
structure is managed by the PropertyBuilder, that means when the
PropertyBuilder runs out of scope, the description structure is
invalid! That’s why other builder classes want the builder directly and
not the build description.