I'm trying to add two options to the encounter menu for when the player encounters a village being raided and he is neither a part of the attacking nor defending faction. The menu is called
Looking further into how the listeners are called shows that they are called in a linked list in an instance of
If the call order of listeners is somehow integral to other parts of bannerlord and can't be changed, I want to know what the proper way to modify the
"join_encounter"
and it is created with the non-serialized listener OnSessionLaunchedEvent
in the EncounterGameMenuBehavior
class. In my mod I use the same listener to add the menu options, but get a KeyNotFoundException
, and debugging further reveals that by the time my code is called, only 46 menus have been created, none of them being the one I want to add options to. I tried the other listeners that have access to an instance of CampaignGameStarter
, but the same error happens, sometimes with even less menus having been loaded.Looking further into how the listeners are called shows that they are called in a linked list in an instance of
MbEvent<T>
and are executed in a first-in-last-out order. So basically, since my OnSessionLaunchedEvent
listener is added last, it's called before the OnSessionLaunchedEvent
listener in EncounterGameMenuBehavior
, hence the KeyNotFoundException
since the code that creates that menu hasn't yet been called by the time my code is called. I found a workaround by accessing the current CampaignGameStarter
instance with SandBoxManager.Instance.GameStarter
in a TickEvent
listener, but this doesn't seem like the right way to do it, and adding an extra TickEvent
listener probably isn't too good for performance. This problem doesn't seem to happen when modifying other menus from what I've heard in the modding discord.If the call order of listeners is somehow integral to other parts of bannerlord and can't be changed, I want to know what the proper way to modify the
"join_encounter"
menu is, since the solution I have now doesn't feel right, but it also doesn't seem right that my listeners should be called before native ones. If this behavior is not intended by the devs, then I hope they change it to make modding the "join_encounter"
menu as easy as modding other native menus.