From 544e4ad6e72fa117cb16aa3db4d22ff8a4ca7184 Mon Sep 17 00:00:00 2001 From: SokyranTheDragon Date: Tue, 20 Jan 2026 21:12:35 +0100 Subject: [PATCH] Delay syncing of world object caravan actions to prevent mod errors Loading non-vanilla world objects too early can cause us to do stuff like loading graphics or accessing defs too early. This can cause bugs and errors in mods, so I've delayed patching of those objects using `LongEventHandler.ExecuteWhenFinished`. --- Source/Client/Syncing/Game/SyncActions.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Client/Syncing/Game/SyncActions.cs b/Source/Client/Syncing/Game/SyncActions.cs index 62a755c50..b5b20a220 100644 --- a/Source/Client/Syncing/Game/SyncActions.cs +++ b/Source/Client/Syncing/Game/SyncActions.cs @@ -25,8 +25,12 @@ void Error(string error) if (CaravanActionConfirmationType == null) Error($"Could not find type: {nameof(CaravanArrivalActionUtility)}.<>c__DisplayClass0_1"); - SyncWorldObjCaravanMenus = RegisterActions((WorldObject obj, Caravan c) => obj.GetFloatMenuOptions(c), ActionGetter, WorldObjectCaravanMenuWrapper); - SyncWorldObjCaravanMenus.PatchAll(nameof(WorldObject.GetFloatMenuOptions)); + // Patch in a long event, otherwise it causes errors with mods that are loading resources + LongEventHandler.ExecuteWhenFinished(() => + { + SyncWorldObjCaravanMenus = RegisterActions((WorldObject obj, Caravan c) => obj.GetFloatMenuOptions(c), ActionGetter, WorldObjectCaravanMenuWrapper); + SyncWorldObjCaravanMenus.PatchAll(nameof(WorldObject.GetFloatMenuOptions)); + }); } private static ref Action ActionGetter(FloatMenuOption o) => ref o.action;