Common Issues
- All generate garbage collection
- Can cause memory fragmentation
- Performance degrades with large datasets
Specialized Unity Collections
- SerializedDictionary: Editor-friendly, great for config data
- ObservableList: Perfect for UI-bound collections
- CircularBuffer: Ideal for command history, rolling stats
- ObjectPool: Must-have for spawning systems
Issues:
- More complex than standard collections
- Require careful implementation
High Performance (Native)
- NativeArray: Burst-compatible, no GC overhead
- NativeList: Dynamic size without the GC cost
- NativeHashMap: High-performance lookups in Jobs
Issues:
- Must manually manage memory (Dispose)
Pro Tips:
- Always profile before optimizing
- Start simple (List/Array) before going native
- Use ObjectPools for frequently spawned objects
- Don't forget to Dispose() native collections!
Common Pitfalls:
- Using List<T> in performance-critical loops
- Forgetting to pre-allocate capacities
- Missing Dispose() calls on Native collections
- Over-engineering with complex structures too early