Skip to content
Pablo Rodriguez

Ai Spawner System

Create a robust AI spawning system that handles enemy placement and respawning:

  • Sphere Visualization: Shows spawner location for level designers (hidden in game)
  • Static Variables: Actor class, spawn delay, position validation
  • Actor Variable: Selectable AI character class to spawn
  • Spawn Delay: 3-second default delay before spawning
  • Instance Editable: Allow per-spawner customization in level editor

Ensure AI spawns on valid ground surfaces:

// Safe Spawn Location Detection
OnSpawnerActivation() {
start_location = GetActorLocation() + Vector(0, 0, 500);
end_location = GetActorLocation() - Vector(0, 0, 500);
LineTraceForObjects(start_location, end_location, [WorldStatic, WorldDynamic]);
spawn_location = hit_location + Vector(0, 0, 100); // Slight elevation
SpawnActor(Actor_Class, spawn_location, GetActorRotation());
}

This system prevents AI from spawning inside geometry or falling through the world.

Create dedicated AI controller for enhanced AI behavior:

  • Blueprint: AIController_Coursera
  • Auto Possess: Set to “Placed in World or Spawned”
  • Integration: Apply to all AI characters in class defaults

Create interface for spawner-AI communication:

  • Function: Respawn
  • Purpose: AI characters call this when they die
  • Implementation: Restart spawn delay timer

Connect AI death to respawn system:

// AI Death Respawn Chain
AI_Character.F_Dead() {
spawner = GetOwner(); // Set during spawn
spawner.Interface_Respawn();
// Delay destruction to allow respawn setup
TimerEvent(5_seconds) {
DestroyActor(Self);
}
}

Establish proper ownership between spawner and AI:

  • Spawn Actor: Set spawner as owner of spawned AI
  • Override Controller: AI controller automatically becomes owner, must override
  • Interface Function: Interface_Set_AI_Owner for proper owner assignment

Implement configurable spawn timing:

  • Event Begin Play: Trigger initial spawn after delay
  • Respawn Delay: Same delay applies to respawn after AI death
  • Variable Delay: Instance-editable spawn timing per spawner

Ensure AI can navigate level properly:

  • Placement: Cover entire playable area
  • Visualization: Press ‘P’ to see navigation mesh
  • AI Movement: AI can only move within nav mesh bounds
  • Level Design: Ensure nav mesh covers intended AI patrol areas

Position spawners strategically throughout levels:

  • Enemy Distribution: Spread spawners for varied encounters
  • Difficulty Scaling: Place stronger enemies in challenging locations
  • Respawn Logic: Consider player progression when enemy respawns
  • Navigation Access: Ensure spawned AI can reach intended areas
  • Varied Spawners: Different spawners for different AI types
  • Class Selection: Choose appropriate AI character class per spawner
  • Spawn Timing: Vary spawn delays to prevent synchronized enemy waves

Test spawner system thoroughly:

  • Ground Detection: Verify AI spawns on solid ground
  • Navigation: Confirm AI can move after spawning
  • Respawn Cycle: Test death-respawn cycle works correctly
  • Owner Relationships: Ensure proper spawner-AI connections
  • Spawn Limits: Monitor total AI count in level
  • Cleanup: Ensure dead AI properly destroys
  • Memory Management: Prevent accumulation of unused AI references

The AI spawner system provides flexible, level-designer-friendly enemy placement with robust respawn mechanics that support dynamic gameplay while maintaining performance and reliability.