Skip to main content

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

FieldPurpose
sourceTextureTexture that contains the encoded TSMP frame.
payloadByteTextureRender texture used by codec shaders when decoding payload bytes.
codecHandlersCodec components available to the decoder. The header codecId selects the handler.
applyEveryFrameRuns decode from the component update loop. Disable it when another script calls DecodeNow().
skipDuplicateFramesIgnores a frame if its header frame index already ran.
flipYFlips texture sampling for capture paths that invert the image.
useHeaderPayloadLayoutUses header payload metadata to size readback. Keep enabled for normal use.
payloadBytesOverrideManual payload byte count for test paths.
decodeSafetyModeExtra 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:

  1. Read the header pixels.
  2. Validate magic, version, payload layout, and CRC.
  3. Select a codec handler by codecId.
  4. Decode payload bytes.
  5. Parse network messages.
  6. 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

MemberMeaning
lastFrameValidLast frame passed all decode stages.
lastHeaderValidHeader was valid before payload decode.
lastErrorLast decoder error or warning text.
lastNetworkMessageCountNumber of messages found in the decoded network frame.
lastAppliedVariableCountNumber of variables applied to behaviours.
lastRpcCallCountNumber of RPC messages dispatched.
lastCodecIdCodec ID read from the last valid header.
lastFrameIndexFrame index read from the header.
lastPayloadBytesPayload byte count used by the decoder.

Binding application

The decoder uses binding arrays generated by TSMPSetup. Each binding maps:

  • networkId
  • variableHash
  • 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.None on 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.