Timberborn-Modding-Central / TimberAPI

The one and only
https://timberapi.com
GNU General Public License v3.0
32 stars 18 forks source link

[0.5.4.2] Configurator triggered before assets loading #70

Closed ihsoft closed 1 year ago

ihsoft commented 1 year ago

I've been migrating an old mod to Update 4 and got hit by error that the assest for the tool icon doesn't exist (BottomBarModuleProvider in configurator). The asset was set to load InGame. The configurator is annoteded with [Configurator(SceneEntrypoint.InGame)].

After some troubleshooting, it turned out that the asset loading works kind of unexpected. Here is the log after triggering the saved game load :

[Error  : Unity Log] ******* CONFIGURE
[Error  : Unity Log] ******* BottomBarModuleProvider: GET!
[Info   : TimberAPI] Assets unloaded for MainMenu
[Info   : TimberAPI] Assets loaded for InGame, Total prefixes loaded: 9

So, its seems that confiurator is triggered before the related assets get loaded. I'd suggest that the right orded should be:

  1. Unload MainMenu assets.
  2. Load InGame asssets.
  3. Trigger InGame configurators.
KYPremco commented 1 year ago

Does this mod try to access icons from the constructor?

In essense the order is the one you said. But this is in terms of Timberborn.

This means that in the constructor there will be no initialization, this is done by the singleton system. In TimberApi's case ITimberApiSingleton, which is called as very first.

ihsoft commented 1 year ago

Yes, it happen in the constructor. Specifically, here: https://github.com/ihsoft/KyP-timberborn-mods/blob/main/DraggableUtils/Configurators/DraggableUtilsConfigurator.cs#L29. I added configurator annotation to DraggableUtilsConfigurator and expected this class not to be constructed until InGame state is in effect. Apparently, DraggableUtilsConfigurator class gets instantiated before the asset switch. It can be worked around when you know it (and that's what I eventually did), but it looks non-intuitive.

KYPremco commented 1 year ago

I actually don't understand why it was working in update 3. This has not been changed as far I can see on our side since the update. Best guess I could make is that some changes were made and now get's loaded earlier than before.

I tested some small things and it probably would be possible to load the assets earlier but this won't be implemented unless really needed. Because it will have an higher chance of breaking other things by not obying the dependency injection ordering.

Making the ToolGroups like this will also become obsolete with the new feature that will hit before or fast after update 4 is launched.

Tools ToolGroupFactory