TSMPDecoder
TSMPDecoder reads a TSMP texture, validates the header, asks the selected codec to recover payload bytes, and applies variable/RPC messages to bound behaviours.
Use this page when wiring a custom receiver, reading diagnostics, or debugging why a frame was ignored.
Component fields
| Field | Purpose |
|---|---|
sourceTexture | Texture that contains the encoded TSMP frame. |
payloadByteTexture | Render texture used by codec shaders when decoding payload bytes. |
codecHandlers | Codec components available to the decoder. The header codecId selects the handler. |
applyEveryFrame | Runs decode from the component update loop. Disable it when another script calls DecodeNow(). |
skipDuplicateFrames | Ignores a frame if its header frame index already ran. |
flipY | Flips texture sampling for capture paths that invert the image. |
useHeaderPayloadLayout | Uses header payload metadata to size readback. Keep enabled for normal use. |
payloadBytesOverride | Manual payload byte count for test paths. |
decodeSafetyMode | Extra guards for malformed or partial frames. |
TSMPSetup normally assigns sourceTexture, byte textures, codec handlers, and binding arrays.
Header validation
The decoder rejects a frame before payload decode when:
- Magic bytes are not TSMP.
- Header size is not supported.
- Major protocol version is not supported.
- Header CRC does not match.
- Payload size exceeds the available texture layout.
CRC failures are logged as warnings. This helps identify capture corruption without applying bad data.
DecodeNow()
public void DecodeNow()
Decodes one frame immediately. It is safe to call with applyEveryFrame disabled.
The method performs this order:
- Read the header pixels.
- Validate magic, version, payload layout, and CRC.
- Select a codec handler by
codecId. - Decode payload bytes.
- Parse network messages.
- Apply variables and dispatch RPC calls.
ResetDecodeDiagnostics()
public void ResetDecodeDiagnostics()
Clears counters and last-error fields. Use it before a repeatable test or after changing scene wiring.
Diagnostics
| Member | Meaning |
|---|---|
lastFrameValid | Last frame passed all decode stages. |
lastHeaderValid | Header was valid before payload decode. |
lastError | Last decoder error or warning text. |
lastNetworkMessageCount | Number of messages found in the decoded network frame. |
lastAppliedVariableCount | Number of variables applied to behaviours. |
lastRpcCallCount | Number of RPC messages dispatched. |
lastCodecId | Codec ID read from the last valid header. |
lastFrameIndex | Frame index read from the header. |
lastPayloadBytes | Payload byte count used by the decoder. |
Binding application
The decoder uses binding arrays generated by TSMPSetup. Each binding maps:
networkIdvariableHash- value type
- target behaviour
- target field name
- sync direction
When a variable message arrives, the decoder only applies it to matching bindings. When an RPC message arrives, the decoder dispatches it to the matching TSMPNetworkBehaviour.
Runtime rules
- A frame with a valid header but unknown codec ID is ignored.
ReceiveInterpolation.Noneon a target behaviour means received values are ignored for that behaviour.- RPC calls are event-like. Use repeat frames on the encoder if the transport drops frames.
- Decoder logs important runtime failures because inspector fields are not visible in uploaded worlds.