missing player spawn

Guide for missing player spawn

Missing Player Spawn Logic

Problem

When clicking "New Game" in the main menu, the game transitions to GameState::Tutorial but shows a blank screen with only the ground plane and lighting visible. No player character appears.

Investigation

Initial Hypothesis

The tutorial system (src/systems/tutorial.rs) was suspected to be missing player/world spawning logic.

Findings

1. Tutorial System Analysis
  • File: src/systems/tutorial.rs
  • Contains tutorial progression logic, step tracking, and reward systems
  • Does NOT contain any player spawning code
  • Only manages tutorial state, not entity initialization
2. World System Analysis
  • File: src/systems/world/mod.rs
  • Contains setup_world system that spawns ground plane and lighting
  • Runs on Startup schedule (not state-specific)
  • Does NOT spawn player entity
3. Spawning System Analysis
  • File: src/systems/world/spawning.rs
  • Contains spawn_npc and spawn_building functions
  • Does NOT contain player spawning logic
4. Comprehensive Grep Search
Searched for player spawning patterns:
# Search 1: Look for Player component spawning
grep -rn "commands.spawn((Player" src/
# Result: No results found

# Search 2: Look for Player component insertion
grep -rn ".insert(Player)" src/
# Result: No results found

# Search 3: Look for Player::default()
grep -rn "Player::default()" src/
# Result: No results found

# Search 4: Look for any spawn calls in player module
grep -rn "commands.spawn" src/systems/player
# Result: No results found
Conclusion: Player entity spawning logic is completely missing from the codebase.

Why This Wasn't Caught Earlier

  1. Save/Load System Exists: src/systems/save_load.rs contains player state restoration logic, which might have given the impression that player spawning was handled elsewhere
  2. Persistence System: src/systems/player/persistence.rs has a load_game_system that runs on PostStartup and attempts to load player data, but it assumes the player entity already exists
  3. Component Initialization: The ensure_player_components system in src/systems/player/mod.rs adds missing components to existing player entities, but doesn't spawn the player itself

Evidence from Persistence System

File: src/systems/player/persistence.rs (lines 62-94)
fn load_game_system(
    mut _commands: Commands,
    mut player_q: Query<(Entity, &mut Transform, &mut Skills, &mut Inventory), With<Player>>,
) {
    // ... load save file ...
    
    if let Ok((_entity, mut transform, mut skills, mut inventory)) = player_q.get_single_mut() {
        // Restore State
        skills.xp = data.skills;
        inventory.items = data.inventory;
        transform.translation = data.position;
        info!("Game Loaded successfully!");
    } else {
        // Player might not be spawned yet? 
        // PostStartup should run after Startup, so Player should be there.
        warn!("Failed to find Player entity to load data into.");
    }
}
Key observation: The warning message at line 86 shows the developer expected the player to exist by PostStartup, but there's no code to actually spawn it.

Impact

  • Blank Screen: Users see only the world environment (ground, lighting) but no player character
  • No Gameplay: Without a player entity, no gameplay systems can function
  • Tutorial Broken: Tutorial state transitions occur, but the player can't interact with anything
  • Camera Issues: Camera systems expect a player entity to follow, causing potential camera positioning issues

Root Cause

The player entity spawning logic was never implemented. The codebase has:
  • ✅ Player component definition
  • ✅ Player component initialization (adding missing components to existing entities)
  • ✅ Player state persistence (save/load)
  • Player entity spawning (missing)
This is a critical missing piece of the game's initialization flow.