Jump to content

Does OnLoadedSaveGame run every game?


GrimyBunyip

Recommended Posts

Maybe my memory is bad, but did anyone ever say that OnLoadedSaveGame actually runs once *every* time you load? As opposed to what was stated in the examples?

 

I'm looking for a method that runs on every load, as a means to implement a form of version control.

Edited by GrimyBunyip
Link to comment
Share on other sites

From the developer source code in X2DownloadableContentInfo :

/// <summary>
/// This method is run if the player loads a saved game that was created prior to this DLC / Mod being installed, and allows the 
/// DLC / Mod to perform custom processing in response. This will only be called once the first time a player loads a save that was
/// create without the content installed. Subsequent saves will record that the content was installed.
/// </summary>
static event OnLoadedSavedGame()

So it is supposed to only be called once. However, I've noticed that it is being called when the mod was already active in the savefile, and so have taken to writing that check into my OnLoadedSavedGame handler.

 

I certainly wouldn't rely on it being invoked every time the game is loaded, as that may be patched in the future...

Link to comment
Share on other sites

There is definitely something weird going on with this OnLoadedSaveGame() function/event. I traced its origins to XcomOnlineEventMgr.uc and PreloadSaveGameData() event contained within. It calls native function GetDLCInfos and then triggers OnLoadedSaveGame event in every DLC which it thinks is new. Unfortunately, since GetDLCInfos function is native, it's not possible to see how exactly it determines that certain DLC is new.

 

I wrote a small function (just for testing purposes) to see if it was possible to remove the mod from RequiredDLC list.. Basically, I just summoned XcomGameState_CampaignSettings object and then called RemoveRequiredDLC(YourPackageName) on it. This was done in UIAvengerHUD OnInit() in my screen listener, and it seems to work. The game thinks my TestMod is always "new". While I haven't thoroughly tested it yet, it now appears to call OnLoadedSaveGame every time. It also doesn't generate missing DLC message (upon loading a save with mod disabled).

 

I dunno, but maybe this could be useful if your have a tiny mod that just tweaks something, and you don't want causing missing DLC error when users decide to disable the mod.

Link to comment
Share on other sites

I agree with Amineri's comment that it appears to be called every time, and I have also taken the approach of checking for each history object before I add it in the OnLoadedSaveGame handler. The clue to this problem comes from objects which get duplicated. One tester reported that each time they saved a game with the mod active and loaded it again, another set of duplicate proving ground projects appeared. That is an obvious problem, where defining other things like a new weapon type or new tech would not make duplication obvious.

Edited by davidlallen
Link to comment
Share on other sites

That's odd, because in my experience it was only being called once on saved games made without the mod. This is back from my Blademaster Enhancement mod, where I tried putting the "ability insertion" in that method. It would change nothing if I loaded a mod with Blademaster Enhancement already active, but it would change the skill if I loaded a save without it. If I first loaded a save without the mod, then a save with the mod, the change would persist, but that's because I'm replacing templates wholesale.

 

This is one of those "50% of the time, the function runs 100% of the time" situations. I'm personally VERY leery of putting events into it if I want them to absolutely positively run every time a saved game is loaded.

Link to comment
Share on other sites

One tester reported that each time they saved a game with the mod active and loaded it again, another set of duplicate proving ground projects appeared. That is an obvious problem, where defining other things like a new weapon type or new tech would not make duplication obvious.

 

Which Mod is that? There could be other reasons this is happening, you know.

 

So far I haven't been able to make it fire repeatedly without actually altering campaign settings.

Link to comment
Share on other sites

 

 

Which Mod is that? There could be other reasons this is happening, you know.

Current version of playable advent. See the downloadable content info file, where it checks to see if the items exist in history. If you remove this section, you will see the behavior that the proving ground projects duplicate after each save-load. Or, simpler, just put a log statement into the function, and you will see it fire even when a game is loaded which already contained the mod.

http://www.nexusmods.com/xcom2/mods/392/?

Link to comment
Share on other sites

 

Which Mod is that? There could be other reasons this is happening, you know.

Current version of playable advent. See the downloadable content info file, where it checks to see if the items exist in history. If you remove this section, you will see the behavior that the proving ground projects duplicate after each save-load. Or, simpler, just put a log statement into the function, and you will see it fire even when a game is loaded which already contained the mod.

http://www.nexusmods.com/xcom2/mods/392/?

 

 

I honestly don't understand what you are talking about. This is what I found in your DownloadableContentInfo class:

static event OnLoadedSavedGame()
{
	local XComGameStateHistory History;
	local XComGameState NewGameState;
	local XComGameState_HeadquartersXCom OldXComHQState;	
	local XComGameState_HeadquartersXCom NewXComHQState;
	local XComGameState_Unit ItemState;
	local X2CharacterTemplateManager ItemMgr;
	local X2CharacterTemplate ItemTemplate;
	local CharacterPoolManager CharMgr;

	ItemMgr = class'X2CharacterTemplateManager'.static.GetCharacterTemplateManager();
	History = `XCOMHISTORY;	
	NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Adding Units");
	OldXComHQState = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom'));
	NewXComHQState = XComGameState_HeadquartersXCom(NewGameState.CreateStateObject(class'XComGameState_HeadquartersXCom', OldXComHQState.ObjectID));

}

as far as I can tell this does nothing except generating several warnings during compilation, and a Redscreen in game about unsubmitted game state. So, I saved the game. Relaunched the game, and loaded the save. The Redscreen wasn't showing any more which means function isn't running (as intended). I also put a Log statement just to be sure and it wasn't printed either. Most likely something else in your code that causes issues.

Link to comment
Share on other sites

Ah yes, this is more like it.

 

Anyway, I did some tests, and well, function still fires once as expected. Not sure what to make of it.

 

Though I am unclear why you are messing with Templates in there. Wouldn't it be easier to just let the Engine handle template creation? If you extend X2DataSet class or any of its numerous subclasses, CreateTemplates() function inside your class will be called automatically.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...