Skip to content

Archived on 2026-10-24. This is a historical implementation note, not current setup instructions or an active task list. Original claims, code examples, file paths, and completion statements have not all been revalidated. Use the current documentation and issue register for maintenance decisions.

Achievement Debug Logging Implementation

Overview

Added comprehensive debug logging to track player data loading flow and identify the root cause of the NullReferenceException in AchievementManager.LoadAchievement().

Changes Made

1. SaveManager.cs

Added debug logging to track PlayerData creation and loading:

  • CreateNewPlayerData(): Logs when new PlayerData is created and checks if unlockedAchievement dictionary is null
  • LoadNewEncryptedSave(): Logs when loading from file, checks Player state, and lists all saved achievement entries
  • MigrateLegacySaveAsync(): Logs when migrating legacy saves and checks merged dictionary state
  • StartupAsync(): Logs PlayerData state BEFORE invoking OnSaveReady event

2. AchievementManager.cs

Added comprehensive logging to LoadAchievement() method:

  • Checks if achievements list is null
  • Tries to access Save.UnlockedAchievement with exception handling
  • Logs all saved achievement entries with their IDs and unlock status
  • Tracks and reports: loaded count, skipped count, and null achievement objects
  • Logs each individual achievement load operation
  • Catches and reports any exceptions with full stack traces

3. PlayerData.cs

Added logging to InitializeDefaults() method:

  • Logs when each dictionary is initialized
  • Shows the final state of unlockedAchievement dictionary
  • Tracks the initialization process step by step

Expected Log Output

When you run the game, you should see logs like:

[SaveManager] Creating new save data
[PlayerData] Initializing default values - unlockedAchievement
[PlayerData] unlockedAchievement dictionary created with 0 entries
[PlayerData] InitializeDefaults complete - unlockedAchievement entries: 0
[SaveManager] New PlayerData created - unlockedAchievement is null: False
[SaveManager] unlockedAchievement dictionary initialized with 0 entries
[SaveManager] About to invoke OnSaveReady - Player is null: False
[SaveManager] unlockedAchievement is null: False
[SaveManager] unlockedAchievement has 0 entries ready for loading
[AchievementManager] LoadAchievement called
[AchievementManager] achievements list is null: False
[AchievementManager] achievements list count: 10
[AchievementManager] Save.UnlockedAchievement is null: False
[AchievementManager] Save.UnlockedAchievement count: 0
[AchievementManager] Loaded achievement 'ACH_ID_1': unlocked=False
...

Troubleshooting

If you see "Save.UnlockedAchievement is NULL":

  • This indicates the PlayerData object exists but the dictionary wasn't initialized
  • Check the SaveManager logs to see which path was taken (new/load/migrate)

If you see "achievements list is NULL":

  • This indicates AchievementManager.Initialize() wasn't called or received a null list
  • Check AppInitiator.Awake() initialization order

If you see an exception:

  • The full stack trace will show exactly where the error occurred
  • Check if SaveManager.Instance.Player is accessible

Next Steps

  1. Run the game and observe the Unity Console output
  2. Look for any ERROR or WARNING logs
  3. Identify at which step the data becomes null
  4. Based on the logs, we can implement the appropriate fix

Files Modified

  • Assets/Script/App/Core/SaveManager.cs
  • Assets/Script/App/Managers/AchievementManager.cs
  • Assets/Script/TinyChaos/DataModels/PlayerData.cs