ParameterStore (UE)

Updated: 09/05/2024

This page contains statements regarding the alpha version.

Summary

CubismParameterStore can be used to store and restore CubismModel parameters and part values.

If CubismParameterStore is not used, the results of processing values with Expression or other methods may not be correct.
If a value operation such as Expression is performed between restore and save, the result of the value manipulation is saved, so the value is added/multiplied to the restored post-operation value, and the result is not as expected.
When value manipulation is performed outside of restore-to-save, the state before the value was manipulated is restored, so that subsequent manipulation of the value through addition/multiplication will result in the proper result.

Behavior

At the time the model is loaded, all the parameter and part references contained in the model are retrieved and their values are cached.

void UCubismParameterStoreComponent::SaveParameters()
{
	for (UCubismParameterComponent* Parameter : Model->Parameters)
	{
		parameterValues[Parameter->Index] = Parameter->GetParameterValue();
	}

	for (UCubismPartComponent* Part : Model->Parts)
	{
		partOpacities[Part->Index] = Part->Opacity;
	}
}


Also, when values are manipulated in Unreal Editor, the values are cached on a per-parameter or per-part basis.

void UCubismParameterStoreComponent::SaveParameterValue(int32 ParameterIndex)
{
	parameterValues[ParameterIndex] = Model->GetParameter(ParameterIndex)->GetParameterValue();
}

void UCubismParameterStoreComponent::SavePartOpacity(int32 PartIndex)
{
	partOpacities[PartIndex] = Model->GetPart(PartIndex)->Opacity;
}


The cached parameter values and part opacity are restored at the beginning of the frame.

void UCubismParameterStoreComponent::LoadParameters() const
{
	for (UCubismParameterComponent* Parameter : Model->Parameters)
	{
		Parameter->SetParameterValue(parameterValues[Parameter->Index]);
	}

	for (UCubismPartComponent* Part : Model->Parts)
	{
		Part->SetPartOpacity(partOpacities[Part->Index]);
	}
}


Values are cached only at limited times, and component updates involving manipulation of parameter values and part opacity are essentially set to run after restoration.

This ensures that these operations do not accumulate in each frame.

AddTickPrerequisiteComponent(Model->ParameterStore); // must be updated after parameters loaded
Was this article helpful?
YesNo
Please let us know what you think about this article.