My mod's settings involve making settings for certain traits. I hold these in a Dictionary mapping TraitDefs to values of an enum. I try to save the Dictionary inside the ExposeData() of my ModSettings subclass, like so:
Data saves correctly. However, when the game tries to load the data when the game starts up, it seems to do so before it's loaded the TraitDef data, so I get many copies of this error:
Could not load reference to RimWorld.TraitDef named AnnoyingVoice [or whatever]
At the time of trait loading, DefDatabase<TraitDef>.DefCount is 0, so the Defs really haven't been loaded. But I saved them using LookMode.Def, so I really have no idea what the proper way to save Defs is, if not that. How can I fix this error? Or do I have to work around it and save the defName instead, then manually load it later? (This would be a pain to implement and I'd really rather avoid it if possible.)
Code Select
public class PCCSettings : ModSettings
{
[...]
Dictionary<TraitDef, TraitSetting> traitSettings = new Dictionary<TraitDef, TraitSetting>();
[...]
public override void ExposeData()
{
[...]
Scribe_Collections.Look(ref traitSettings, "traitSettings", LookMode.Def, LookMode.Value);
if (traitSettings == null) traitSettings = new Dictionary<TraitDef, TraitSetting>();
}
Data saves correctly. However, when the game tries to load the data when the game starts up, it seems to do so before it's loaded the TraitDef data, so I get many copies of this error:
Could not load reference to RimWorld.TraitDef named AnnoyingVoice [or whatever]
At the time of trait loading, DefDatabase<TraitDef>.DefCount is 0, so the Defs really haven't been loaded. But I saved them using LookMode.Def, so I really have no idea what the proper way to save Defs is, if not that. How can I fix this error? Or do I have to work around it and save the defName instead, then manually load it later? (This would be a pain to implement and I'd really rather avoid it if possible.)