Skip to main content

TSMPNetworkBehaviour

Namespace: K13A.TSMP.Udon

Base type for TSMP-synchronized behaviours.

Use this when a component should participate in TSMP message routing. It provides a network ID, receive interpolation policy, lifecycle hooks, and SendTransRPC.

Fields

FieldTypeUse
networkIdushortRoutes payload messages to this behaviour.
receiveInterpolationReceiveInterpolationModeControls receive behaviour.
continuousInterpolationRatefloatSmoothing rate for continuous receive mode.
transRpcEncoderTSMPEncoderEncoder used by SendTransRPC. Assigned by setup.
lastVariableHashuintLast received variable hash.
lastRpcHashuintLast received RPC hash.
lastRpcNetworkIdushortNetwork ID for the last received RPC.
lastRpcArgumentCountintArgument count for the last received RPC.
lastRpcMethodNamestringMethod name for the last received RPC.

Do not assign transRpcEncoder manually in normal scenes. Let TSMPSetup assign it.

ReceiveInterpolationMode

ValueMeaning
NoneIgnore received values.
DiscreteApply received values directly.
ContinuousStore targets and interpolate where supported.

Built-in components decide how to use Continuous. Custom components should check receiveInterpolation before applying received data.

Lifecycle methods

MethodCalled when
TSMPBeforeEncode()Before encoder reads [TransSync] fields.
OnTSMPVariableReceived()After decoder applies a synchronized field.
OnTSMPVariableChanged(uint variableHash)From the base receive handler.
OnTSMPRpcReceived()After decoder dispatches a TSMP RPC.
OnTSMPRpc(uint rpcHash)From the base RPC receive handler.

Typical custom component flow:

public override void TSMPBeforeEncode()
{
packedBytes = BuildPacket();
}

public override void OnTSMPVariableReceived()
{
if (receiveInterpolation == ReceiveInterpolationMode.None)
return;

ApplyPacket(packedBytes);
OnTSMPVariableChanged(lastVariableHash);
}

Utility methods

MethodUse
IsTSMPActive()Returns enabled and active-in-hierarchy state.
GetReceiveInterpolationStep()Returns a clamped 0..1 interpolation step.
SendTransRPC(string methodName, RPCTarget target)Queue an RPC event through TSMP.

RPCTarget

ValueBehaviour
LocalExecute locally only.
RemoteQueue for receivers only.
AllExecute locally and queue for receivers.

SendTransRPC hashes the method name and queues it through the assigned encoder. The receiving side dispatches by method name after decode.

Example RPC

public override void Interact()
{
SendTransRPC(nameof(ToggleObject), RPCTarget.All);
}

public void ToggleObject()
{
target.SetActive(!target.activeSelf);
}