Sprint 4: Pause / Save / New Game
# ๐ Sprint 4: Save/Load System - COMPLETED
**Sprint Duration:** Week 4
**Status:** โ COMPLETE
**Completion Date:** November 29, 2025
---
## ๐ Sprint Goal
Implement a complete save/load system that persists all game state between sessions, including visit counts, building activations, and animal discoveries.
---
## โ Completed Features
### 1. Save/Load Core System
- โ JSON-based serialization using Unity's JsonUtility
- โ GameSaveData structure with visit counts, animals, and buildings
- โ Auto-save every 2 minutes
- โ Manual save via pause menu "Save Game" button
- โ Auto-save on application quit
- โ Save file path: `Application.persistentDataPath/outback_save.json`
### 2. Visit System Persistence
- โ All zone visit counts save/load correctly
- โ Visit data restored to VisitManager on game start
- โ Buildings activate based on loaded visit thresholds
### 3. Building Activation Persistence
- โ Activated building IDs tracked at runtime
- โ Buildings restore activation state on load
- โ BuildingIDHelper for easy ID assignment in Inspector
- โ Integration with ActivatableObject component
### 4. Animal Discovery Persistence
- โ Discovered animals save/load correctly
- โ Discovery HUD updates after loading save data
- โ Animal icons show correct discovered/undiscovered state
- โ "X/4 Animals Discovered" counter persists
### 5. Pause Menu with Save/Load UI
- โ ESC key opens pause menu
- โ "Resume" button returns to game
- โ "Save Game" button triggers manual save
- โ "New Game" button resets game state
- โ "Instructions" panel with game controls
- โ Time.timeScale pauses game properly
### 6. New Game Functionality
- โ Deletes save file
- โ Resets all manager states
- โ Reloads scene cleanly without crashes
- โ Destroys DontDestroyOnLoad singletons before reload
### 7. Debug Features
- โ F5 = Manual save
- โ F6 = Manual load
- โ F7 = Delete save
- โ F8 = New game
- โ Comprehensive console logging
---
## ๐ Bugs Fixed
### Bug #1: New Game Crash ๐ฅ โ โ FIXED
**Problem:** Clicking "New Game" crashed Unity with duplicate singleton warnings
**Root Cause:** DontDestroyOnLoad singletons (VisitManager, AnimalDiscoveryManager, GameSaveManager) persisted across scene reload, creating duplicate instances
**Solution:** Modified `GameSaveManager.StartNewGame()` to destroy all DontDestroyOnLoad singletons BEFORE calling `SceneManager.LoadScene()`
**Files Modified:** `GameSaveManager.cs`
---
### Bug #2: Animal Discovery UI Reset ๐ฆ โ โ FIXED
**Problem:** After save/load, HUD showed "0/4 Animals Discovered" instead of correct count
**Root Cause:** Save data loaded correctly into AnimalDiscoveryManager, but HUD never updated because no events were fired during load
**Solution:** Added `Start()` method to HUDController that queries discovery count after save data loads (delayed by one frame to ensure load completes first)
**Files Modified:** `HUDController.cs`
---
## ๐ Technical Implementation
### Architecture Pattern: Observer Pattern
- GameSaveManager observes ActivatableObject activations
- HUDController observes AnimalDiscoveryManager events
- Clean separation of concerns
### Design Patterns Used
- **Singleton:** GameSaveManager, VisitManager, AnimalDiscoveryManager
- **Observer:** Event-driven updates for UI and state changes
- **Serialization:** GameSaveData as data transfer object
### Code Quality
- โ Follows OOP principles
- โ Follows SOLID principles
- โ Comprehensive error handling
- โ Defensive null checks
- โ Clear code comments
- โ Consistent naming conventions
---
## ๐งช Testing Completed
### Test Case 1: Basic Save/Load
1. Started game (fresh)
2. Discovered 2 animals โ HUD shows "2/4"
3. Visited zones to activate 2 buildings
4. Clicked ESC โ "Save Game"
5. Quit game
6. Restarted game
7. โ HUD showed "2/4 Animals Discovered"
8. โ Buildings remained activated
9. โ Visit counts persisted
### Test Case 2: New Game
1. Loaded game with progress
2. Clicked ESC โ "New Game"
3. โ Scene reloaded cleanly (no crash)
4. โ HUD showed "0/4 Animals Discovered"
5. โ All buildings deactivated
6. โ No duplicate manager warnings
### Test Case 3: Auto-Save
1. Played for 3 minutes
2. Observed console logs
3. โ Auto-save triggered at 2-minute mark
4. โ Save file updated successfully
### Test Case 4: Debug Keys
1. Pressed F5 โ โ Manual save worked
2. Pressed F6 โ โ Manual load worked
3. Pressed F7 โ โ Save deleted
4. Pressed F8 โ โ New game started
---
## ๐ Files Created/Modified
### New Files Created
- `GameSaveData.cs` - Serializable save data structure
- `GameSaveManager.cs` - Save/load system manager
- `BuildingIDHelper.cs` - Inspector helper for assigning building IDs
### Files Modified
- `ActivatableObject.cs` - Added save system integration
- `VisitManager.cs` - Added LoadVisitData() and GetAllVisitData()
- `AnimalDiscoveryManager.cs` - Added LoadDiscoveryData() and ResetAllDiscoveries()
- `HUDController.cs` - Added pause menu, save/load buttons, discovery HUD update on load
- `HUD.uxml` - Added pause menu UI structure
- `HUD.uss` - Added pause menu styling
---
## ๐ Metrics
**Lines of Code Added:** ~800 lines
**Files Created:** 3
**Files Modified:** 6
**Bugs Fixed:** 2 critical
**Test Cases Passed:** 4/4
---
## ๐ฏ Definition of Done - Sprint 4
- [x] Save system persists visit counts
- [x] Save system persists building states
- [x] Save system persists discovered animals
- [x] Auto-save works every 2 minutes
- [x] Manual save/load works via pause menu
- [x] Save on quit works
- [x] New Game button works without crash
- [x] Animal discovery UI updates after loading
- [x] Debug keys functional (F5/F6/F7/F8)
- [x] Code follows OOP/SOLID principles
- [x] No compiler errors/warnings
- [x] All features tested in Play mode
- [x] Code committed to Git with clear messages
---
## ๐ Ready for Sprint 5
Sprint 4 is complete with all features working as expected. The save/load system is robust, tested, and ready for production.
**Next Sprint Focus:** Add 3 new animals (Koala, Frillneck Lizard, Platypus) to expand discovery content.
---
## ๐ Lessons Learned
### What Went Well โ
- Observer pattern made event-driven updates clean and maintainable
- Singleton managers kept global state management simple
- GameSaveData structure with helper methods made serialization straightforward
- Comprehensive logging made debugging efficient
### Challenges Overcome ๐ง
- DontDestroyOnLoad singleton lifecycle during scene reload (fixed with proper destruction)
- Event firing during save data load (fixed with delayed UI update)
- Method naming consistency across codebase (resolved with compatibility aliases)
### Future Improvements ๐ก
- Consider player position save/load for spawn location
- Add save file backup system
- Implement save file version migration for future updates
- Add cloud save integration (future feature)
---
## ๐ฎ Player Experience
The save/load system is completely transparent to players:
- Game automatically saves progress every 2 minutes
- Progress persists between sessions without player action
- Manual save available via pause menu for peace of mind
- New Game option allows fresh starts
- No loading screens or save confirmations interrupt gameplay
**Sprint 4 delivers a polished, production-ready save system!** โจ
---
**Sprint Completed By:** Andrew (Developer) + Claude (AI Assistant)
**Sprint Review Date:** November 29, 2025
**Status:** APPROVED - Ready for Sprint 5
Get Sunday Drive
Sunday Drive
Relaxing driving simulator
| Status | In development |
| Author | andrew-leary |
| Genre | Simulation |
| Tags | Driving, Relaxing |
More posts
- Devlog: โ
Sprint 3 - Completed14 days ago
- Devlog: October 24 202536 days ago
- Devlog02: Sprint 2 completed53 days ago
- House and animals addedApr 08, 2025
- Demo addedApr 08, 2025
Leave a comment
Log in with itch.io to leave a comment.