codeAPI Reference
s&box MorphState: Morph value persistence
MorphState Component API Reference
MorphState persists morph values on a GameObject so they survive over the network and duplication.
Type Signature
CSHARP
[Title("Morph State")]
[Category("Rendering")]
public sealed class MorphState : Component
{
[Property]
public string SerializedMorphs { get; set; }
protected override void OnStart();
public void ApplyBatch(string morphsJson);
public void ApplyPreset(string morphsJson);
public void Capture(SkinnedModelRenderer smr);
public void Apply();
}Properties
- string SerializedMorphs { get; set; } - Serialized morph values as JSON. Persisted for dupes/saves but not synced over network.
Methods
OnStart()
Applies the stored morph values to the SkinnedModelRenderer on spawn.ApplyBatch(string morphsJson)
Applies a partial morph batch on the host, then broadcasts to all clients via RPC. Does not reset existing morphs.ApplyPreset(string morphsJson)
Applies a full morph preset on the host (resets all morphs first), then broadcasts to all clients via RPC.Capture(SkinnedModelRenderer smr)
Snapshots all current morph values from the SkinnedModelRenderer into SerializedMorphs as JSON.Apply()
Applies the stored SerializedMorphs to the first SkinnedModelRenderer found. Called on spawn/dupe restore.Usage
CSHARP
// Capture current morph state
var morphState = go.AddComponent<MorphState>();
morphState.Capture(smr);
// Apply a partial morph batch
morphState.ApplyBatch(Json.Serialize(new Dictionary<string, float>
{
["mouth_open"] = 0.5f,
["blink_left"] = 0.1f
}));
// Apply a full preset (resets all first)
morphState.ApplyPreset(Json.Serialize(new Dictionary<string, float>
{
["mouth_open"] = 1.0f,
["blink_left"] = 0.0f
}));Notes
- SerializedMorphs is persisted for duplication and save/load
- Morph values are synced via RPC when ApplyBatch/ApplyPreset is called
- ApplyPreset resets all morphs before applying new values
- ApplyBatch only applies the specified morphs without resetting
- Used by tools that manipulate skinned model morphs
Was this helpful?