Versions Compared

Key

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

...

Here are some simple examples of how you could do that:

Await the CavrnusSpaceConnection (as usual)

Before you can do anything, you will need to wait for your Space to connect. We explain how to do this here: https://cavrnus.atlassian.net/wiki/spaces/CSM/pages/837451792873398431/Unreal+-+Binding+and+Displaying+Properties#Await-the-CavrnusSpaceConnection

Posting Single Property Updates

To give the most basic example of Posting a Property update, let’s assume we have a button in the UI to “Turn Object Red”.

...

The function that button would call would simply be this:

public
Code Block
languagecpp
void UPropertyButton::TurnObjectRed()
{
	spaceConn.UCavrnusFunctionLibrary::PostColorPropertyUpdate(SpaceConnection, ContainerName, PropertyName, Color.redFLinearColor::Red);
}

Posting Continuous Property Updates

As you will recall from our Core Concepts, every change that is ever made to a space is stored in the Journal. This is very useful for being able to view/understand the history of what has happened in a Space. However, it has limitations. Specifically, if you are Posting updates to the Journal every frame then the Journal will eventually become very big and performance will eventually be impacted.

For this, let’s take a Color Wheel as an examplelook at the Unreal Editor Color Picker:

...

In this Color Wheel Dialog there are a lot of dials, sliders, and input fields, all modifying the same value. If a user were to click and drag across one of the sliders it could result in hundreds, perhaps even thousands of Property updates being Posted. To fix this, we recommend using Transient updates. Transient updates begin a CavrnusLivePropertyUpdate. These updates will be sent to other users, but will not be stored in the Journal.

...

On the other hand, if somehow the interaction was invalid or ended up with bad data, you can call Cancel any time to clear the changes and make it like it never happened.

private CavrnusLivePropertyUpdate<Color> liveColorUpdate
Code Block
languagecpp
// Class definition includes the following declaration.
// UPROPERTY()
// UCavrnusLiveColorPropertyUpdate* LiveColorUpdater = null;

//We The justcolor clickedadjustment thewidget Colorhas Wheelbeen publicopened
void BeginInteractingWithColorWheel(Color colorUColorChangeWidget::OnMouseCaptureBegin()
{
	
  CurrentValue = SavedValue;
  if (liveColorUpdate!LiveColorUpdater)
== null) 	{
		liveColorUpdate
    LiveColorUpdater = spaceConn.UCavrnusFunctionLibrary::BeginTransientColorPropertyUpdate(SpaceConnection, ContainerName, PropertyName, colorCurrentValue);
	  }
}

// This will trigger every frame while the user is dragging thea color wheelvalue around
publicchanges
void UseColorWheel(Color colorUColorChangeWidget::OnValueChanged(FLinearColor Value)
{
	  CurrentValue = Value;
  
  if (liveColorUpdateLiveColorUpdater)
!= null) 	{
		liveColorUpdate.UpdateWithNewData(color);
	
    LiveColorUpdater->UpdateWithNewData(Value);
  }
}

// The user releases their mouse
public void ReleaseColorWheel(Color colorwidget has been closed by committing the change.
void UColorChangeWidget::OnSaveButtonClicked()
{
  SavedValue = if(liveColorUpdate != null)CurrentValue;
  
  if {(LiveColorUpdater)
  {
     liveColorUpdateLiveColorUpdater.Finish();
    LiveColorUpdater    liveColorUpdate = null;

   }
}

//If The thewidget colorhas wheelbeen closed unexpectedly, we should cancelby canceling the live change
as if it never happened.
public void CancelColorWheel()
{void UColorChangeWidget::OnMouseCaptureEnd()
{
  CurrentValue = SavedValue;
  
  if (liveColorUpdate LiveColorUpdater!= null)
 
  {
        liveColorUpdateLiveColorUpdater.Cancel();
       LiveColorUpdater liveColorUpdate = null;
 
  }
}