Skip to content

Previous Override Iteration

LinkCache offers an easy way to dig deeper past winning overrides into the load order and access the non-winning versions of records from previous mods.

Some important concepts to consider when Resolving:

Scoping Type

Resolve Target

ResolveAll

This call will loop over all versions of a record. If given a ResolveTarget, it will start looping at the end given. For example, ResolveTarget.Winning will return the winning record first, and then loop all the way to the originating version last.

IFormLinkGetter<INpcGetter> myLink = ...;
ILinkCache myLinkCache = ...;

foreach (var record in myLink.ResolveAll(myLinkCache))
{
    Console.WriteLine($"EditorID is {record.EditorID}");
}
IFormLinkGetter<INpcGetter> myLink = ...;
ILinkCache myLinkCache = ...;

foreach (var record in myLink.ResolveAll(myLinkCache))
{
    Console.WriteLine($"EditorID is {record.EditorID}");
}

Context Variants Preferred

This call only returns the records themselves. The context variants will be able to inform you on where the record came from

ResolveAllContexts

ResolveAllContexts is an alternative that returns ModContext objects instead, which have a lot more information/tooling about where a record came from.

IFormLinkGetter<INpcGetter> formLink = ...;

foreach (var npcRecordContext in npcLink.ResolveAllContexts<ISkyrimMod, ISkyrimModGetter, INpc, INpcGetter>(myLinkCache))
{
    Console.WriteLine($"The Npc's EditorID is {npcRecordContext.Record.EditorID} in mod {npcRecordContext.ModKey}");
}

Refer to the Mod Contexts documentation for more information about type requirements on the call

Mod Contexts

Best Practices

It is important to only loop over what you need. This allows the Link Cache to only parse as deep into the Load Order as it needs.

Enumerable Laziness

// Break out of your loops if you're done
foreach (var npcRecord in npcLink.ResolveAll(myLinkCache))
{
    if (HasWhatINeed(npcRecord))
    {
        // Stop looping
        break;
    }
}

// Or only take what you're interested in
INpcGetter[] recordWithPreviousOverride = npcLink.ResolveAll(myLinkCache)
    // This limits the looping to two levels deep, at most
    .Take(2)
    // Solidifies the results into an array for reuse
    .ToArray();

// Got the winning record
var winningRecord = recordWithPreviousOverride[0];
if (recordWithPreviousOverride.Length > 1)
{
    // And it has a previous override, too
    var previousOverride = recordWithPreviousOverride[1];
}