Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

...

- Code Sample

Example case - color and height of a flag.

FlagActor.h:

TODO: WRITE
Code Block
languagecpp
#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:

Code Block
languagecpp
#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;
}