MONSTER_SPAWNING_SETUP.md 3.7 KB

Monster Spawning Setup

What Was Fixed

Monsters were being created as data objects but not being visualized in the scene. Here's what's now in place:

New Components Created

  1. MonsterView.cs — Visual representation of a single monster

    • Renders as a colored square (placeholder, swappable for real art)
    • Color comes from the Monster template's color setting
    • Destroys itself when defeated
  2. MonsterSpawner.cs — Orchestrates monster spawning

    • Listens to MazeGenerator.RoomGenerated events
    • When a room with an encounter is created, spawns MonsterView GameObjects
    • Scatters monsters around the room in a circle pattern
    • Organizes spawned monsters in the hierarchy under "SpawnedMonsters"
  3. Updated MazeSceneBuilder.cs

    • Added [RequireComponent(typeof(MonsterSpawner))]
    • MonsterSpawner is now automatically added to the scene

How It Works

Data Flow (Already Existing)

MazeGenerator.BuildRoom()
  → if ShouldSpawnMonster() [70% chance by default]
    → Creates MonsterEncounter with 1-3 monsters (random)
    → Stores in room.Encounter

Visualization Flow (NEW)

MonsterSpawner.OnRoomGenerated(room)
  → if room.Encounter exists and has monsters
    → For each monster, spawn MonsterView GameObject
    → Position them in a circle around the room center
    → Organize in hierarchy

Configuration

In MazeGenerator (Inspector)

  • Encounter Chance: 0.7 (70% of rooms have monsters)
  • Min Monsters Per Room: 1
  • Max Monsters Per Room: 3
  • Monster Pool: Loaded from Resources/Characters/Monsters/

In Goblin Template (or Any Monster Asset)

  • Color: Determines visual appearance color
  • Base Stats: Health, attack, defense, etc.
  • Starting Equipment: Optional weapon/armor
  • Possible Loot: Items dropped when defeated

Creating New Monster Types

  1. In Unity Editor, right-click in Project folder → Create → Maze Gen → Monster
  2. Set the monster's properties (name, color, stats, loot)
  3. Save to Assets/Resources/Characters/Monsters/YourMonster.asset
  4. The system will automatically load it via Resources.LoadAll<Monster>()

Visual Hierarchy

When playing, you'll see:

MazeSceneBuilder
├── SpawnedMonsters (container)
│   ├── Room0_Monsters
│   │   ├── Goblin (MonsterView component)
│   │   ├── Goblin
│   │   └── ...
│   ├── Room1_Monsters
│   │   ├── Goblin
│   │   └── ...
│   └── ...
├── [Room GameObjects from MazeSceneBuilder]
└── ...

Next Steps (Optional Enhancements)

  • Add animations when monsters spawn
  • Add combat interaction when agents encounter monsters
  • Add different monster types/prefabs
  • Implement monster AI movement
  • Add monster defeat feedback (sound, particles)
  • Replace placeholder colored squares with real art

Troubleshooting

"Monsters still don't appear"

  • ✓ Check Console for errors during play
  • ✓ Verify Monster assets exist in Assets/Resources/Characters/Monsters/
  • ✓ Check that encounterChance > 0 in MazeGenerator
  • ✓ Ensure MazeSceneBuilder has MonsterSpawner component (should be automatic)

"Monster assets can't be found"

  • Make sure assets are saved in Assets/Resources/Characters/Monsters/
  • Assets must inherit from Monster class (ScriptableObject)
  • Restart Unity Editor after adding new monster assets

"Compilation error about MonsterSpawner"

  • This is just IDE lag — the MonsterSpawner script is in the correct namespace
  • Play the game anyway — it will compile fine in Unity