BindXPropertyValue (Unreal Engine)

- Declaration

static FCavrnusBinding BindColorPropertyValue(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, FColorPropertyUpdated OnPropertyUpdated);

static FCavrnusBinding BindBooleanPropertyValue(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, FBoolPropertyUpdated OnPropertyUpdated);

static FCavrnusBinding BindFloatPropertyValue(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, FFloatPropertyUpdated OnPropertyUpdated);

static FCavrnusBinding BindStringPropertyValue(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, FStringPropertyUpdated OnPropertyUpdated);

static FCavrnusBinding BindVectorPropertyValue(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, FVectorPropertyUpdated OnPropertyUpdated);

static FCavrnusBinding BindTransformPropertyValue(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, FTransformPropertyUpdated OnPropertyUpdated);

Delegates Options:

DECLARE_DYNAMIC_DELEGATE_ThreeParams(FStringPropertyUpdated, FString, Value, FString, ContainerName, FString, PropertyName);
typedef TFunction<void(const FString&, const FString&, const FString&)> CavrnusStringFunction;

DECLARE_DYNAMIC_DELEGATE_ThreeParams(FBoolPropertyUpdated, bool, Value, FString, ContainerName, FString, PropertyName);
typedef TFunction<void(bool, const FString&, const FString&)> CavrnusBoolFunction;

DECLARE_DYNAMIC_DELEGATE_ThreeParams(FFloatPropertyUpdated, float, Value, FString, ContainerName, FString, PropertyName);
typedef TFunction<void(float, const FString&, const FString&)> CavrnusFloatFunction;

DECLARE_DYNAMIC_DELEGATE_ThreeParams(FVectorPropertyUpdated, FVector4, Value, FString, ContainerName, FString, PropertyName);
typedef TFunction<void(const FVector4&, const FString&, const FString&)> CavrnusVectorFunction;

DECLARE_DYNAMIC_DELEGATE_ThreeParams(FColorPropertyUpdated, FLinearColor, Value, FString, ContainerName, FString, PropertyName);
typedef TFunction<void(const FLinearColor&, const FString&, const FString&)> CavrnusColorFunction;

DECLARE_DYNAMIC_DELEGATE_ThreeParams(FTransformPropertyUpdated, FTransform, Value, FString, ContainerName, FString, PropertyName);

typedef TFunction<void(const FTransform&, const FString&, const FString&)> CavrnusTransformFunction;

- Description

Triggers an event when the property changes, plus an initial event when first bound.

When you are done with your Bind function and want it to stop, you should call Unhook() on the FCavrnusBinding returned by it. Otherwise it will keep triggering the event whenever changes arrive from the server.

- Blueprint Sample

BindPropertyValue.png
BindColorPropertyValue and Unbind

- Code Sample

Example case - color and height of a flag.

FlagActor.h:

#include "GameFramework/Actor.h" #include "Types/CavrnusSpaceConnection.h" #include "Types/CavrnusBinding.h" #include "FlagActor.generated.h" class UMaterialInstanceDynamic; UCLASS() class MODULE_API AFlagActor : public AActor { GENERATED_BODY() public: void InitializeProperties(FString& InContainerName, FCavrnusSpaceConnection& InSpaceConnection); UFUNCTION(BlueprintImplementableEvent) void OnFlagHeightChanged(); UFUNCTION() void FlagHeightPropertyUpdated(float PropertyValue); UFUNCTION() void FlagColorPropertyUpdated(FLinearColor PropertyValue); private: UPROPERTY() LinearColor FlagColor; UPROPERTY() float FlagHeight; UMaterialInstanceDynamic* FlagFabricMaterial; // Objects that synchronize properties should be created using UCavrnusFunctionLibrary::SpawnObject. This gives the spawner back the properties container name that this object will use in the journal. FString ContainerName; FCavrnusSpaceConnection SpaceConnection; FCavrnusBinding FlagHeightBinding; FFloatPropertyUpdated OnFlagHeightPropertyUpdated; FCavrnusBinding FlagColorBinding; FColorPropertyUpdated OnFlagColorPropertyUpdated; };

FlagActor.cpp:

#include "FlagActor.h" #include "CavrnusFunctionLibrary.h" #include "Materials/MaterialInstanceDynamic.h" void AFlagActor::InitializeProperties(FString& InContainerName, FCavrnusSpaceConnection& InSpaceConnection) { ContainerName = InContainerName; SpaceConnection = InSpaceConnection; OnFlagHeightPropertyUpdated.BindUFunction(this, GET_FUNCTION_NAME_CHECKED(AFlagActor, FlagHeightPropertyUpdated)); FlagHeightBinding = UCavrnusFunctionLibrary::BindFloatPropertyValue(SpaceConnection, ContainerName, "FlagHeight", OnFlagHeightPropertyUpdated); OnFlagColorPropertyUpdated.BindUFunction(this, GET_FUNCTION_NAME_CHECKED(AFlagActor, FlagColorPropertyUpdated)); FlagColorBinding = UCavrnusFunctionLibrary::BindColorPropertyValue(SpaceConnection, ContainerName, "FlagColor", OnFlagColorPropertyUpdated); } void AFlagActor::FlagHeightPropertyUpdated(float PropertyValue) { FlagHeight = PropertyValue; OnFlagHeightChanged(); } void AFlagActor::FlagColorPropertyUpdated(FLinearColor PropertyValue) { FlagColor = PropertyValue; if (FlagFabricMaterial != nullptr && FlagFabricMaterial->IsValidLowLevel()) { FlagFabricMaterial->SetVectorParameterValue(TEXT("Color"), FlagColor); } }

Related pages