Skip to content

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.Instance automatically discovers an existing pool in the scene or instantiates a persistent root [FuzzyOptimizer_PoolManager] that survives scene loading transitions via DontDestroyOnLoad().
  • 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

MethodDescription
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

PropertyDefaultPurpose
Initial Audio Voices16Initial prewarmed AudioSource instances created on startup.
Max Audio Voices32Hard 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 / MethodDescription
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:

  1. Camera Frustum & Distance Culling: Particle systems outside the camera frustum or beyond Max Particle Distance are paused. Systems paused by the limiter resume automatically when re-entering the camera view. Systems paused by your game code remain paused.
  2. 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

SettingDefaultDescription
Max Global Particles3000Global particle ceiling across all visible emitters (minimum 100).
Enable Budget ThrottlingtrueThrottles furthest emitters when exceeding budget. If disabled, logs a diagnostic warning instead.
Never ThrottleList<ParticleSystem>Explicit list of emitters exempt from throttling (e.g. player weapon effects, critical spell impacts).
Enable Frustum CullingtruePauses emitters whose bounding volumes lie outside the camera frustum.
Enable Distance CullingtruePauses emitters located beyond Max Particle Distance.
Max Particle Distance75 mDistance threshold for particle simulation culling.

Public API Reference

API MemberPurpose
InstanceAccesses 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.
CurrentGlobalParticlesReturns 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

PropertyDefaultPurpose
Spherical CullingtrueMeasures distance from camera origin rather than the planar projection, eliminating corner-of-screen pop-in when rotating.
Small Details Distance25 mCull distance applied to the SmallProps layer.
Medium Props Distance60 mCull distance applied to the MediumProps layer.
Large Structures Distance250 mCull distance applied to the LargeProps layer.
Custom Layer DistancesArray [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:

  • CylindricalY Mode: Rotates only around the Y axis, keeping the billboard upright (ideal for distant trees, lamp posts, fences, and characters).
  • Spherical Mode: 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.