Line 37: |
Line 37: |
| | | |
| ==Changes== | | ==Changes== |
| + | ===Mods are loaded earlier=== |
| + | Mods were previously loaded right before the first <tt>UpdateTicking</tt> event, which is too late for some changes like intercepting core assets. SMAPI 3.0 loads them much earlier, before the game is fully initialised. '''Do not depend on game fields like <tt>Game1.objectInformation</tt> having a valid value in your <tt>Entry</tt> method!''' You can use the <tt>GameLaunched</tt> event for that instead. See [[Modding:Modder Guide/APIs/Mod structure#Mod entry]] for more info. |
| + | |
| + | For example, let's say you have code like this: |
| + | <source lang="c#"> |
| + | public override void Entry(IModHelper helper) |
| + | { |
| + | this.Config = helper.ReadConfig<ModConfig>(); |
| + | |
| + | CommunityCenter communityCenter = (CommunityCenter)Game1.getLocationFromName("CommunityCenter"); |
| + | this.VaultRoomID = communityCenter.getAreaNumberFromName("Vault"); |
| + | } |
| + | </source> |
| + | |
| + | That code will fail in SMAPI 3.0, because no locations are loaded yet. This code could be rewritten like this: |
| + | <source lang="c#"> |
| + | public override void Entry(IModHelper helper) |
| + | { |
| + | this.Config = helper.ReadConfig<ModConfig>(); |
| + | |
| + | helper.Events.GameLoop.GameLaunched += this.OnGameLaunched; |
| + | } |
| + | |
| + | private void OnGameLaunched(object sender, GameLaunchedEventArgs args) |
| + | { |
| + | CommunityCenter communityCenter = (CommunityCenter)Game1.getLocationFromName("CommunityCenter"); |
| + | this.VaultRoomID = communityCenter.getAreaNumberFromName("Vault"); |
| + | } |
| + | </source> |
| + | |
| ===API changes=== | | ===API changes=== |
| {| class="wikitable" | | {| class="wikitable" |