Commit Graph

4 Commits

Author SHA1 Message Date
e1d81baf60 Fix ModalManager crash when asset bundle is missing
Problem: When Main.TransitionTo() tried to show an error modal about
missing multiplayer UI, it triggered ModalManager's static constructor
which tried to instantiate modalUIPrefab. Since the asset bundle was
missing, modalUIPrefab was null, causing:

System.TypeInitializationException: The type initializer for
'KCM.ModalManager' threw an exception.
---> System.ArgumentException: The Object you want to instantiate is null.
  at KCM.ModalManager..cctor () [0x00017]

This created a catch-22: couldn't show error modal about missing UI
because the modal itself needed the missing UI.

Root cause:
ModalManager static constructor didn't check if modalUIPrefab was null
before trying to instantiate it. ShowModal() and HideModal() also
assumed modalInst was always initialized.

Solutions:

ModalManager static constructor (lines 25-30):
- Add null check for PrefabManager.modalUIPrefab
- If null, log warning and return early
- Set instantiated = true to prevent re-initialization
- Log success message when initialization works

ShowModal() method (lines 55-59):
- Check if modalInst is null before using it
- If null (couldn't initialize), just log the modal content
- Format: "MODAL (not shown - UI missing): Title - Message"
- Prevents crash and preserves the error message in logs

HideModal() method (lines 81-84):
- Add null check before calling SetActive
- Safe to call even if modal not initialized

Results:
 No crash when modal UI is missing
 Error messages still logged even if not shown visually
 Graceful degradation throughout the mod
 ModalManager can be safely called from anywhere
 Clear logging shows what modals would have appeared

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-14 21:28:18 +01:00
3124f82a2f alap 2025-12-14 21:08:19 +01:00
3a7b81bfd7 save 2025-12-14 21:04:22 +01:00
679c3c9a52 first commit 2025-12-13 14:28:35 +01:00