Ship preload: a mod ship that fails to load or assemble is skipped, not fatal
PreloadAsync rethrew on the first failing hull, so one bad package faulted Loading and no mod ship could spawn. Each hull now loads in its own try: a failure destroys its partial visual, is logged with the hull's name, and the rest still preload, as Compose skips a bad package. The play smoke installs the package beside a broken sibling that composes but cannot assemble (its map icon moved onto a meshless muzzle node) and proves the sibling has no prototype while the good ship spawns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fc73d7abcd
commit
6709b06e2e
3 changed files with 69 additions and 16 deletions
|
|
@ -14,7 +14,9 @@ public static class ShipModShips
|
|||
private static readonly Dictionary<CultRecordKey, GameObject> Prototypes = new Dictionary<CultRecordKey, GameObject>();
|
||||
private static CultCache _catalog;
|
||||
|
||||
// Set by Preload; complete when every prototype is ready, faulted when any mod ship failed to import or assemble.
|
||||
// Set by Preload; complete when every hull that could be built has its prototype. A mod ship that fails to import or
|
||||
// assemble is skipped and logged, as Compose skips a bad package, so it never stops the rest; Loading faults only
|
||||
// when the preload itself cannot run.
|
||||
public static Task Loading { get; private set; } = Task.CompletedTask;
|
||||
|
||||
public static Task Preload(CultCache catalog, string modsRoot)
|
||||
|
|
@ -39,18 +41,19 @@ public static class ShipModShips
|
|||
if (Application.isPlaying) Object.DontDestroyOnLoad(root);
|
||||
foreach (var hull in hulls)
|
||||
{
|
||||
var package = ShipModCatalog.PackageOf(catalog, hull, modsRoot);
|
||||
var visual = await ShipModVisual.LoadAsync(package, root.transform);
|
||||
ShipModVisual.Instance visual = null;
|
||||
try
|
||||
{
|
||||
var package = ShipModCatalog.PackageOf(catalog, hull, modsRoot);
|
||||
visual = await ShipModVisual.LoadAsync(package, root.transform);
|
||||
visual.Root.SetActive(false);
|
||||
Assemble(visual, package.Hull, package.Visual, template);
|
||||
Prototypes[catalog.RefOf(hull).Key] = visual.Root;
|
||||
}
|
||||
catch
|
||||
catch (Exception error)
|
||||
{
|
||||
visual.Destroy();
|
||||
throw;
|
||||
visual?.Destroy();
|
||||
Debug.LogError($"Mod ship {hull.Name} skipped: {error.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue