What It Means & How to Fix It in UE5
🧠 Why You’re Seeing This Error
This error means your shader is using more samplers (texture samplers) than the hardware or shader model allows.
In HLSL/UE5, a sampler is an object that lets you sample textures. Most platforms and shader models have strict limits on how many samplers you can bind in a single shader.
SM5 and most desktop GPUs allow up to 16 samplers. Exceeding this limit causes X4509.
💥 Example Error Message
error X4509: maximum number of samplers exceeded (16)
🛠️ Common Shader Scenarios That Cause This
❌ Too Many Texture Samplers
Texture2D Texture0;
SamplerState Sampler0;
...
Texture2D Texture16;
SamplerState Sampler16;
float4 color = Texture16.Sample(Sampler16, uv); // ❌ Sampler16 is the 17th — exceeds limit
❌ Material Graphs with Too Many Unique Texture Samples
In Material Editor:
- Using more than 16 unique Texture Sample nodes in a single shader path (like Base Color) will trigger this
- Each unique sample with a different sampler counts against the limit
❌ Sampler Redundancy
// Reusing the same texture but with different samplers still adds to the count
MyTexture.Sample(SamplerA, uv);
MyTexture.Sample(SamplerB, uv); // ❌ counts as 2 samplers
✅ How to Fix X4509 in UE5 – Step-by-Step
✔️ 1. Reduce the Number of Unique Samplers
Use fewer Texture2D
+ SamplerState
pairs:
// ✅ Preferred
Texture2D MyTexture;
SamplerState SharedSampler;
float4 a = MyTexture.Sample(SharedSampler, uv1);
float4 b = MyTexture.Sample(SharedSampler, uv2);
This only uses one sampler.
✔️ 2. Use Shared Samplers Where Possible
When sampling the same texture, reuse the sampler:
float4 a = Tex.Sample(SamplerLinear, uv1);
float4 b = Tex.Sample(SamplerLinear, uv2); // ✅ still only one sampler used
✔️ 3. Merge Multiple Textures Into an Atlas (Advanced)
If you’re sampling multiple textures with separate samplers:
- Combine them into a texture atlas
- Use UV offsets and scales to simulate multiple textures with a single sampler
✔️ 4. Optimize Materials (if error occurs in Material Editor)
- Reduce the number of Texture Sample nodes in each material path
- Share the same texture across roughness, specular, metallic channels (packed maps)
- Disable unused shader paths (e.g., disable tessellation or other features you’re not using)
✅ Summary: How to Fix “error X4509: maximum number of samplers exceeded” in UE5
Cause | Fix |
---|---|
More than 16 samplers used | Reduce number of Texture2D + SamplerState pairs |
Same texture sampled with different samplers | Reuse the same sampler across all samples |
Too many textures in material | Use texture atlases or combine packed maps |
Excessive Texture Sample nodes | Simplify material graph and remove unused sample paths |