Tier 2 Series 105

105G: The Factory Exam

Capstone Exam
"The factory line is jammed. The spawned enemies are flooding the Hierarchy root, the game crashes with a NullReference on startup, and the bullets fly forever until the game runs out of memory. Identify the three critical failures."

Target Asset for Audit

FRAGILE_CODE_DETECTED
using UnityEngine;

public class Spawner : MonoBehaviour {
    public GameObject enemyPrefab;
    public GameObject bulletPrefab;

    // Audit Requirement: Lesson 105E (Awake/Start)
    // Error 1: Race Condition
    // Using Start to setup variables that others might need immediately.
    void Start() {
        SetupStats();
    }

    void Update() {
        if (Input.GetKeyDown(KeyCode.Space)) {
            // Audit Requirement: Lesson 105C (Parenting)
            // Error 2: Hierarchy Pollution
            Instantiate(enemyPrefab, transform.position, Quaternion.identity);
        }
        
        if (Input.GetButton("Fire1")) {
            // Audit Requirement: Lesson 105D (Recycler)
            // Error 3: Memory Leak
            Instantiate(bulletPrefab, transform.position, Quaternion.identity);
            // No Destroy() call exists for the bullet.
        }
    }
}

Supervisor's Certification

Authenticated Pilot
pilot_2c2fdd81706e1acc
Session Secure

Failure Point #1

Lifecycle Order Failure

The AI used `Start` for self-setup. Command it to use `Awake`.

Failure Point #2

Hierarchy Pollution

The enemies are spamming the root level. Command the AI to use a Parent container.

Failure Point #3

Memory Leak

The bullets are never destroyed. Command the AI to set a lifetime.