07. Runtime Components
← Previous: Optimization Tools | Next: Reports, CI & Build Check →
Overview
The runtime components of FuzzyOptimizer reside inside the FuzzyOptimizer.Runtime assembly definition (.asmdef). They are lightweight, allocation-free, and designed to safely ship inside production player builds on all target platforms.
Attach any runtime component via the Unity Inspector:
Add Component > FuzzyOptimizer > [Component Name]ZeroAllocPoolManager
Namespace: FuzzyLogicLabs.FuzzyOptimizer.Runtime.MemoryShield
A high-throughput object and audio pooling framework designed to replace runtime GameObject.Instantiate() and GameObject.Destroy() calls, eliminating garbage collection spikes during intense gameplay.
- Singleton Lifecycle:
ZeroAllocPoolManager.Instanceautomatically discovers an existing pool in the scene or instantiates a persistent root[FuzzyOptimizer_PoolManager]that survives scene loading transitions viaDontDestroyOnLoad(). - Audio Voice Stealing: Includes a dynamic audio pooling system. If all pooled voices are busy, the oldest active voice is recycled automatically.
Public API Reference
| Method | Description |
|---|---|
Prewarm(GameObject prefab, int count) | Pre-allocates and deactivates count instances during scene loading or initialization. |
Spawn(GameObject prefab, Vector3 pos, Quaternion rot, Transform parent = null) | Retrieves an inactive instance from the pool (or instantiates a new one if exhausted) and activates it. |
Despawn(GameObject instance) | Deactivates the instance and returns it cleanly to its designated pool queue. |
PlayAudio(AudioClip clip, Vector3 pos, float volume = 1f, float pitch = 1f) | Plays an audio clip on a recycled spatial AudioSource voice. |
Inspector Properties
| Property | Default | Purpose |
|---|---|---|
| Initial Audio Voices | 16 | Initial prewarmed AudioSource instances created on startup. |
| Max Audio Voices | 32 | Hard upper ceiling for simultaneous active audio voices before voice-stealing takes effect. |
Code Example
using UnityEngine;using FuzzyLogicLabs.FuzzyOptimizer.Runtime.MemoryShield;
public class WeaponController : MonoBehaviour{ [SerializeField] private GameObject bulletPrefab; [SerializeField] private AudioClip fireSfx;
private void Start() { // Pre-allocate 50 bullets during startup ZeroAllocPoolManager.Instance.Prewarm(bulletPrefab, 50); }
public void FireWeapon() { var pool = ZeroAllocPoolManager.Instance;
// Spawn bullet from pool with zero GC allocations GameObject bullet = pool.Spawn(bulletPrefab, transform.position, transform.rotation);
// Auto-despawn after 3 seconds bullet.GetComponent<PoolableObject>().DespawnAfter(3.0f);
// Play audio effect using pooled voice pool.PlayAudio(fireSfx, transform.position, volume: 0.9f); }}PoolableObject
Attached automatically to any object spawned by the pool. You can also attach it directly to your project prefab to establish a default lifetime.
| Property / Method | Description |
|---|---|
autoDespawnTime (Inspector) | When $> 0$, automatically returns the GameObject to the pool after this many seconds. |
DespawnAfter(float seconds) | Schedules an automatic return to the pool after the specified delay. |
ReturnToPool() | Returns the GameObject to its parent pool immediately. |
IsPooled (Read-only) | Returns true if the instance is currently managed by a pool. |
GlobalVFXBudgetLimiter
Namespace: FuzzyLogicLabs.FuzzyOptimizer.Runtime.MemoryShield
An intelligent runtime manager that keeps aggregate scene particle costs strictly within platform hardware limits. It operates at a decoupled frequency of 10 Hz (10 evaluations per second) and produces zero garbage collection allocations.
The limiter performs dual-stage optimization:
- Camera Frustum & Distance Culling: Particle systems outside the camera frustum or beyond
Max Particle Distanceare paused. Systems paused by the limiter resume automatically when re-entering the camera view. Systems paused by your game code remain paused. - Dynamic Particle Budget Throttling: When total active particles exceed
Max Global Particles, the limiter pauses emission on the furthest visible emitters. Live particles complete their lifetime naturally, preventing sudden visual pops. When count falls below 85% of budget, emitters are smoothly restored nearest-first.
Inspector Configuration
| Setting | Default | Description |
|---|---|---|
| Max Global Particles | 3000 | Global particle ceiling across all visible emitters (minimum 100). |
| Enable Budget Throttling | true | Throttles furthest emitters when exceeding budget. If disabled, logs a diagnostic warning instead. |
| Never Throttle | List<ParticleSystem> | Explicit list of emitters exempt from throttling (e.g. player weapon effects, critical spell impacts). |
| Enable Frustum Culling | true | Pauses emitters whose bounding volumes lie outside the camera frustum. |
| Enable Distance Culling | true | Pauses emitters located beyond Max Particle Distance. |
| Max Particle Distance | 75 m | Distance threshold for particle simulation culling. |
Public API Reference
| API Member | Purpose |
|---|---|
Instance | Accesses the active global VFX limiter. |
RegisterSystem(ps) | Registers dynamically spawned particle systems into limiter tracking. |
UnregisterSystem(ps) | Removes a particle system and restores its original emission/pause state. |
SetThrottleExempt(ps, exempt) | Toggles exemption status for a specific emitter at runtime. |
CurrentGlobalParticles | Returns current total live particle count across the scene. |
LayerDistanceCuller
Namespace: FuzzyLogicLabs.FuzzyOptimizer.Runtime.Culling
Requires an attached Unity Camera component.
Configures native engine-level Camera.layerCullDistances on Awake(). Culled GameObjects are dropped directly by the native C++ rendering pipeline, incurring zero per-object C# script cost.
Configuration Properties
| Property | Default | Purpose |
|---|---|---|
| Spherical Culling | true | Measures distance from camera origin rather than the planar projection, eliminating corner-of-screen pop-in when rotating. |
| Small Details Distance | 25 m | Cull distance applied to the SmallProps layer. |
| Medium Props Distance | 60 m | Cull distance applied to the MediumProps layer. |
| Large Structures Distance | 250 m | Cull distance applied to the LargeProps layer. |
| Custom Layer Distances | Array [32] | Granular per-layer distance array (0–31). Set to 0 to inherit camera far clip. |
// Programmatically adjust culling distances at runtime:var culler = Camera.main.GetComponent<LayerDistanceCuller>();culler.ApplyPreset(small: 15f, medium: 45f, large: 180f);BillboardRotator
Namespace: FuzzyLogicLabs.FuzzyOptimizer.Runtime.Culling
Drives single-quad baked billboards to always face the active camera:
CylindricalYMode: Rotates only around the Y axis, keeping the billboard upright (ideal for distant trees, lamp posts, fences, and characters).SphericalMode: Full 3D orientation towards the camera eye (ideal for stars, distant orbs, smoke puffs).- Reverse Facing: Inverts facing vector if geometry was baked backwards.
MultiAngleBillboard
Namespace: FuzzyLogicLabs.FuzzyOptimizer.Runtime.Culling
Requires an attached Renderer component.
The runtime controller for baked 8-directional impostors. It evaluates the angle between the camera vector and the GameObject orientation, then offsets the material’s UV coordinates to display the matching angle slice from the baked atlas with zero runtime memory allocations.
BenchmarkViewpointMarker
Namespace: FuzzyLogicLabs.FuzzyOptimizer.Runtime.Benchmark
Marks physical camera positions and orientations for the automated Optimize & Measure FPS benchmark tool. Place markers at key gameplay locations. The component contains no update loop and carries zero runtime overhead in builds.
FuzzyLogger
Namespace: FuzzyLogicLabs.FuzzyOptimizer.Runtime.Core
Unified logging utility stamping all console output with the [FuzzyOptimizer] prefix. Adjust FuzzyLogger.MinLogLevel in settings to filter editor log verbosity.