The most powerful and easy-to-use swarm intelligence system for Unity. Create flocking birds, schooling fish, robot swarms, crowd simulations, and emergent AI behaviors with minimal code.
- Classic Flocking - Separation, alignment, and cohesion behaviors
- Advanced Steering - Seek, flee, pursue, evade, wander, and arrive
- Formation Control - Line, circle, V-formation, and custom patterns
- Obstacle Avoidance - Smart navigation around static and dynamic obstacles
- Target Following - Individual and group target tracking
- Predator-Prey - Complete ecosystem simulations
- Multi-threaded - Unity Job System integration for massive performance
- GPU Acceleration - Compute shader support for 10,000+ agents
- Spatial Partitioning - Optimized neighbor detection with octrees and grids
- LOD System - Automatic quality scaling based on distance and performance
- Object Pooling - Zero garbage collection for smooth performance
- DOTS Compatible - Entity Component System integration for ultimate performance
- 3D & 2D Support - Works seamlessly in both 3D and 2D projects
- Physics Integration - Collision detection and response with Unity Physics
- Animation Support - Automatic animation blending based on movement states
- Sound Integration - Spatial audio for realistic swarm soundscapes
- Visual Effects - Built-in particle systems and trail renderers
- Networking Ready - Multiplayer synchronization for shared swarm experiences
- Visual Editor - Intuitive inspector interfaces with real-time previews
- Behavior Trees - Node-based behavior design with visual scripting
- Debugging Tools - Comprehensive visualization and performance monitoring
- Example Scenes - 20+ ready-to-use examples and templates
- Extensive Documentation - Complete API reference with video tutorials
- C# Source - Full source code access for customization
# Via Unity Package Manager
Window โ Package Manager โ + โ Add package from git URL
https://github.com/ruvnet/unity-swarm-ai.git// Add SwarmManager to an empty GameObject
var manager = gameObject.AddComponent<SwarmManager>();
manager.agentCount = 100;
manager.spawnRadius = 10f;// Create a capsule and add SwarmAgent component
var agent = GetComponent<SwarmAgent>();
agent.maxSpeed = 5f;
agent.perceptionRadius = 3f;
agent.separationWeight = 1.5f;
agent.alignmentWeight = 1.0f;
agent.cohesionWeight = 1.0f;That's it! You now have 100 agents flocking together with emergent group behavior.
- Installation Guide - Step-by-step setup instructions
- Tutorial - Your first swarm in 10 minutes
- API Reference - Complete code documentation
- Performance Guide - Optimization tips and best practices
- Troubleshooting - Common issues and solutions
All examples are included in the Examples/ folder:
| Scene | Description | Agent Count | Complexity |
|---|---|---|---|
| BasicFlocking | Simple boids simulation | 100 | Beginner |
| ObstacleAvoidance | Navigation around obstacles | 150 | Beginner |
| FormationFlying | Military-style formations | 50 | Intermediate |
| PredatorPrey | Ecosystem with hunters and prey | 200 | Intermediate |
| MassiveSwarm | GPU-accelerated 5000+ agents | 5000+ | Advanced |
| 2D Schooling | Fish school in 2D space | 300 | Intermediate |
| Smart Crowds | Human crowd simulation | 500 | Advanced |
| Robot Swarms | Coordinated multi-robot system | 100 | Advanced |
- RTS Games - Unit formations and group movement
- Action Games - Enemy swarms and ally squads
- Simulation Games - Wildlife, traffic, crowds
- Space Games - Fleet formations and space creatures
- Educational Games - Physics and biology demonstrations
- Architectural Visualization - Crowd flow simulation
- Research - Collective behavior studies
- Training Simulations - Military and emergency response
- Data Visualization - Particle system representations
- AI Research - Swarm intelligence experiments
// Main swarm management
SwarmManager // Central coordination and spawning
SwarmAgent // Individual agent with AI behaviors
SwarmBehavior // Pluggable behavior system
// Advanced features
SpatialPartition // High-performance neighbor detection
SwarmFormation // Predefined and custom formations
ObstacleAvoidance // Smart navigation system
SwarmDebugger // Visual debugging and profiling| Agents | Architecture | Performance | Use Case |
|---|---|---|---|
| 1-100 | MonoBehaviour | 60+ FPS | Prototyping, mobile |
| 100-1000 | Job System | 60+ FPS | Most games |
| 1000-5000 | ECS + Burst | 60+ FPS | Large simulations |
| 5000+ | GPU Compute | 60+ FPS | Massive crowds |
public class CustomBehavior : SwarmBehavior
{
public override Vector3 CalculateForce(SwarmAgent agent, List<SwarmAgent> neighbors)
{
// Your custom AI logic here
return customForce;
}
}// Switch between formations dynamically
swarmManager.SetFormation(FormationType.VFormation);
swarmManager.SetFormation(FormationType.Circle, radius: 10f);
swarmManager.SetFormation(customFormation); // User-defined patterns// Different agent types with unique behaviors
SwarmSpecies predators = new SwarmSpecies("Sharks", 10);
SwarmSpecies prey = new SwarmSpecies("Fish", 200);
SwarmSpecies neutral = new SwarmSpecies("Dolphins", 20);
ecosystem.AddSpecies(predators, prey, neutral);Tested on Unity 2022.3, Windows 11, RTX 3080, Intel i7-12700K
| Agent Count | FPS (MonoBehaviour) | FPS (Jobs) | FPS (GPU) | Memory Usage |
|---|---|---|---|---|
| 100 | 240+ | 240+ | 240+ | 15 MB |
| 500 | 180 | 240+ | 240+ | 45 MB |
| 1,000 | 90 | 200+ | 240+ | 85 MB |
| 5,000 | 20 | 120 | 240+ | 180 MB |
| 10,000 | 8 | 60 | 200+ | 350 MB |
We welcome contributions! See our Contributing Guide for details.
git clone https://github.com/ruvnet/unity-swarm-ai.git
cd unity-swarm-ai
# Open project in Unity 2021.3+- Bug Reports: Use GitHub Issues with reproduction steps
- Feature Requests: Describe your use case and expected behavior
- Performance Issues: Include profiler data and system specs
This project is licensed under the MIT License - see the LICENSE file for details.
- โ Free for commercial use in games and applications
- โ Redistribute with your projects
- โ Modify the source code as needed
- โ Enterprise support available for large teams
- ruvnet - Original creator and maintainer
- Contributors - See GitHub Contributors
Built upon decades of swarm intelligence research:
- Craig Reynolds' Boids (1986)
- Modern flocking algorithms and optimizations
- Unity's Data-Oriented Technology Stack (DOTS)
Special thanks to our amazing community of developers, researchers, and enthusiasts who help make this plugin better every day!
- ๐ Homepage: unity-swarm-ai.com
- ๐ Documentation: docs.unity-swarm-ai.com
- ๐ฌ Discord: Join our community
- ๐บ YouTube: Video tutorials
- ๐ฆ Twitter: @unity_swarm_ai
Ready to create amazing swarm behaviors? ๐ฆโจ
โฌ๏ธ Download Now or try our Live Web Demo
Making swarm intelligence accessible to every developer ๐