Evolving NPCs: Creating AIs that Loot Items and Improve Stats in Unity
3 de octubre de 2026
Have you ever felt that your game enemies are just static punching bags waiting to be hit? In indie development, the difference between a mediocre game and a memorable one lies in world reactivity. If an NPC sees a better sword on the ground, why would they ignore it?
Today we are diving deep into how to use the Modular AI Behaviour Kit to create a dynamic looting system where your AIs do not just patrol—they evolve by collecting items and improving their stats in real-time.
1. The Philosophy of Modular Composition
Most developers try to program a monolithic AI with thousands of lines of code. With our Kit, we change that approach to Personality by Composition. To make an NPC pick up items, we only need to combine three basic senses:
- PlayerDetector (reconfigured): To detect objects in a specific layer (‘Loot’).
- SimpleChase: To drive the NPC toward the detected object.
- AIController: To manage the transition between ‘Patrol’ and ‘Looting’.
2. Setting Up Object Perception
The PlayerDetector component is extremely versatile. Although its name suggests it only detects players, it works with any LayerMask. To create a scavenger NPC, we set up a second detector on the same GameObject:
3. The Brain: Managing the Looting State
The AIController acts as the conductor. When the loot detector fires the OnTargetDetected event, the controller must pause the patrol and activate the chase toward the item.
// Logic example in the AIController
_lootDetector.OnTargetDetected.AddListener((lootItem) => {
ChangeState(AIState.Chasing);
_chase.ManualStartChase(lootItem);
});
4. Stat Evolution (MAS Integration)
Picking up the object is only half the battle. The real magic happens when the NPC improves. This is where Modular Attributes & Stats (MAS) comes into play. Upon reaching the item, we trigger an event that applies an AttributeModifier to the NPC.
Conclusion
Creating believable AIs does not have to be a technical nightmare. By using an event-based modular approach, you allow your NPCs to interact with the environment organically. The Modular AI Behaviour Kit gives you the muscles and the senses; you just have to define the ambition of your creatures.
Level up your game today
Get this asset on the Unity Asset Store.