PostXPropertyUpdate (Unreal Engine)

- Declaration

static void PostColorPropertyUpdate(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, FLinearColor PropertyValue);

static void PostBoolPropertyUpdate(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, bool PropertyValue);

static void PostFloatPropertyUpdate(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, float PropertyValue);

static void PostStringPropertyUpdate(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, FString PropertyValue);

static void PostVectorPropertyUpdate(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, FVector4 PropertyValue);

static void PostTransformPropertyUpdate(FCavrnusSpaceConnection SpaceConnection, const FPropertiesContainer& ContainerName, const FString& PropertyName, FTransform PropertyValue);

- Description

Updates the property value at the given path and synchronizes the data to the server.

This is the most common/simple way of changing a property’s value. However, since it writes to the journal, it is best to not post hundreds or thousands of these changes in rapid succession. Instead when, say, dragging an object between two points, consider using BeginTransientXPropertyUpdate instead.

- Blueprint Sample

In this example, clicking on a Spawner object creates an object and selects a randomized starting location, immediately posting the transform to the journal.

PostTransformPropertyUpdate.png
Post Transform Property Update

- 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: virtual void Tick( float DeltaSeconds ) override; // Setting a new team color changes the color immediately, and also triggers a movement animation of the flag re-raising UFUNCTION(BlueprintCallable) void SetTeamColor(LinearColor NewColor); private: UPROPERTY() LinearColor FlagColor; UPROPERTY() float FlagHeight; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) float MaxFlagHeight; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) float FlagRaiseTime; UMaterialInstanceDynamic* FlagFabricMaterial; float FlagAnimationTimeRemaining = -1.0f; // 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; };

FlagActor.cpp:

#include "FlagActor.h" #include "CavrnusFunctionLibrary.h" #include "Materials/MaterialInstanceDynamic.h" void AFlagActor::Tick( float DeltaSeconds ) { Super::Tick(DeltaSeconds); if (FlagAnimationTimeRemaining > 0.0f) { float NewTimeRemaining = FlagAnimationTimeRemaining - DeltaSeconds; if (NewTimeRemaining <= 0.0f) { FlagHeight = MaxFlagHeight; FlagAnimationTimeRemaining = -1.0f; } else { float PctMoved = 1.0f - (NewTimeRemaining / FlagAnimationTimeRemaining); FlagHeight += PctMoved * (MaxFlagHeight - FlagHeight); FlagAnimationTimeRemaining = NewTimeRemaining; } UCavrnusFunctionLibrary::PostFloatPropertyUpdate(SpaceConnection, ContainerName, "FlagHeight", FlagHeight); } } void AFlagActor::SetTeamColor(LinearColor NewColor) { FlagColor = NewColor; UCavrnusFunctionLibrary::PostColorPropertyUpdate(SpaceConnection, ContainerName, "FlagColor", FlagColor); if (FlagFabricMaterial != nullptr && FlagFabricMaterial->IsValidLowLevel()) { FlagFabricMaterial->SetVectorParameterValue(TEXT("Color"), FlagColor); } FlagHeight = 0.0f; FlagAnimationTimeRemaining = FlagRaiseTime; }