# Streaming (/docs/es_extended/client/modules/streaming)

`ESX.Streaming` wraps the GTA "request and wait until loaded" pattern. Each function requests an asset, waits until it is loaded and returns it, or returns `nil` if loading fails. Use it before you spawn a model, play an animation or draw a texture.

## Overview [#overview]

| | |
|---|---|
| Resource | `es_extended` (implemented in `esx_lib` as `xLib.streaming`) |
| Side | Client |
| Timeout | `xLib:streamingTimeout` convar, default `10000` ms, `0` waits forever |

Every function has the same shape: `(asset, cb?)`. With `cb`, the function calls `cb(asset)` and returns its result. Without `cb`, it returns the asset. On timeout it returns `nil` and `cb` is not called. The functions block, so call them from a thread.

## Functions [#functions]

### ESX.Streaming.RequestModel [#esxstreamingrequestmodel]

```lua
ESX.Streaming.RequestModel(modelHash, cb)
```

| Name | Type | Description |
|---|---|---|
| `modelHash` | `number \| string` | Model hash or name. Names are hashed with `joaat`. |
| `cb` | `function?` | `function(modelHash)`. |

**Returns:** `number|nil` model hash. `nil` if the model does not exist or timed out.

```lua
local model = ESX.Streaming.RequestModel('a_m_y_business_01')

if model then
    local ped = CreatePed(4, model, 240.0, -862.0, 29.7, 340.0, false, true)
    SetModelAsNoLongerNeeded(model)
end
```

### ESX.Streaming.RequestAnimDict [#esxstreamingrequestanimdict]

```lua
ESX.Streaming.RequestAnimDict(animDict, cb)
```

| Name | Type | Description |
|---|---|---|
| `animDict` | `string` | Animation dictionary. |
| `cb` | `function?` | `function(animDict)`. |

**Returns:** `string|nil`

```lua
ESX.Streaming.RequestAnimDict('mp_arresting', function(dict)
    TaskPlayAnim(ESX.PlayerData.ped, dict, 'idle', 8.0, -8.0, -1, 49, 0.0, false, false, false)
    RemoveAnimDict(dict)
end)
```

### ESX.Streaming.RequestAnimSet [#esxstreamingrequestanimset]

```lua
ESX.Streaming.RequestAnimSet(animSet, cb)
```

Loads a movement clipset (walk style).

| Name | Type | Description |
|---|---|---|
| `animSet` | `string` | Clipset name, for example `move_m@drunk@verydrunk`. |
| `cb` | `function?` | `function(animSet)`. |

**Returns:** `string|nil`

```lua
local walk = ESX.Streaming.RequestAnimSet('move_m@drunk@verydrunk')

if walk then
    SetPedMovementClipset(ESX.PlayerData.ped, walk, 1.0)
end
```

### ESX.Streaming.RequestStreamedTextureDict [#esxstreamingrequeststreamedtexturedict]

```lua
ESX.Streaming.RequestStreamedTextureDict(textureDict, cb)
```

| Name | Type | Description |
|---|---|---|
| `textureDict` | `string` | Texture dictionary. |
| `cb` | `function?` | `function(textureDict)`. |

**Returns:** `string|nil`

```lua
CreateThread(function()
    local dict = ESX.Streaming.RequestStreamedTextureDict('commonmenu')
    if not dict then return end

    while showLogo do
        DrawSprite(dict, 'shop_box_tick', 0.9, 0.1, 0.03, 0.05, 0.0, 255, 255, 255, 255)
        Wait(0)
    end

    SetStreamedTextureDictAsNoLongerNeeded(dict)
end)
```

### ESX.Streaming.RequestNamedPtfxAsset [#esxstreamingrequestnamedptfxasset]

```lua
ESX.Streaming.RequestNamedPtfxAsset(assetName, cb)
```

| Name | Type | Description |
|---|---|---|
| `assetName` | `string` | Particle asset, for example `core`. |
| `cb` | `function?` | `function(assetName)`. |

**Returns:** `string|nil`

```lua
ESX.Streaming.RequestNamedPtfxAsset('core', function(asset)
    UseParticleFxAsset(asset)
    local coords = GetEntityCoords(ESX.PlayerData.ped)
    StartParticleFxNonLoopedAtCoord('exp_grd_bzgas_smoke', coords.x, coords.y, coords.z, 0.0, 0.0, 0.0, 1.0, false, false, false)
end)
```

### ESX.Streaming.RequestWeaponAsset [#esxstreamingrequestweaponasset]

```lua
ESX.Streaming.RequestWeaponAsset(weaponHash, cb)
```

| Name | Type | Description |
|---|---|---|
| `weaponHash` | `number` | Weapon hash, for example `` `WEAPON_PISTOL` ``. |
| `cb` | `function?` | `function(weaponHash)`. |

**Returns:** `number|nil`

```lua
local weapon = ESX.Streaming.RequestWeaponAsset(`WEAPON_PISTOL`)
```

<Callout type="info" title="More in esx_lib">
`xLib.streaming` also has `requestModelWithSpinner(model, message, cb)` and `requestAudioBank(bankName, cb)`. They are not mapped to `ESX.Streaming`. Load `@esx_lib/imports.lua` in your manifest to use them through `xLib`.
</Callout>

## Common issues [#common-issues]

- **Function returns `nil` for a custom vehicle or ped.** The addon resource is not started or the model name is wrong. Check `IsModelInCdimage`.
- **Memory grows over time.** Release assets with the matching `SetModelAsNoLongerNeeded` / `Remove*` native.

## Related [#related]

- [ESX.Game](/docs/es_extended/client/modules/game)
- [Scaleform](/docs/es_extended/client/modules/scaleform)
- [esx_lib](/docs/core/esx_lib)
- [Performance guide](/docs/guides/performance)
