Skip to content

PlayerOcclusionStrategy

Guribo edited this page Jul 11, 2026 · 2 revisions

PlayerOcclusionStrategy

Packages/tlp.udonvoiceutils/Runtime/Core/PlayerAudio/PlayerOcclusion/PlayerOcclusionStrategy.cs

Abstract base class for occlusion behavior — determines how much audio is muffled by obstacles.

Overview

PlayerOcclusionStrategy defines how the system calculates audio clarity when obstacles exist between the listener and a speaker. Two built-in implementations are provided:

Strategy Behavior
DefaultPlayerOcclusion Raycast-based — muffles audio behind walls and players
NullPlayerOcclusion Passthrough — no occlusion (full clarity always)

How to Use

  1. Add a strategy component to your scene (e.g. DefaultPlayerOcclusion)
  2. Assign it to the PlayerOcclusionStrategy field on TLP_PlayerAudioController
  3. The controller uses this strategy for all player voice and avatar audio occlusion

Custom Strategies

To create a custom occlusion strategy:

  1. Create a new UdonSharp class extending PlayerOcclusionStrategy
  2. Override GetAudioClarity — return a value between 0 and 1 (1 = full clarity, 0 = fully muffled)
  3. Add the component to a GameObject in your scene
  4. Assign it to PlayerAudioController.PlayerOcclusionStrategy

GetAudioClarity Parameters

Parameter Description
listenerHead World position of the local player's head
listenerLookDirection Normalized direction the local player is facing
distanceBetweenPlayerHeads Distance between listener and emitter heads
environmentClarity Occlusion impact from environment obstacles (0-1)
playerClarity Occlusion impact from other players (0-1)
playerOcclusionMask Layer mask used for raycasting

Returns: float 0-1 where 1 = no negative impact on clarity.

See Also

Clone this wiki locally