// Management · RimWorld Mod

HAR Character Editor Duplicate Key Fix

HAR Character Editor Duplicate Key Fix mod preview for RimWorld

Fixes the "Could not execute post-long-event action.

Fixes the "Could not execute post-long-event action. Exception: System. ArgumentException: An item with the same key has already been added. Key: XXXXX" error that occurs when editing alien race pawn(Miho, etc.) age/traits/race/backstory with Character Editor while using the updated Humanoid Alien Races (HAR).

Root Cause The updated HAR registers a deferred delegate at the end of ThingDef_AlienRace.ResolveReferences that populates replacerDict using Dictionary.Add, which is not idempotent. Character Editor calls ResolveReferences again at runtime when editing pawns, causing a duplicate key crash.

Fix Approach A Harmony Prefix intercepts ResolveReferences: when replacerDict is already populated (indicating Def loading phase has executed it once), it clears duplicate replacerDict, then allows the method body to execute in full.

Why Not Skip The Method Entirely Skipping the entire ResolveReferences would also skip base.ResolveReferences(), preventing Harmony patches (Prefix/Postfix/Transpiler) attached to the base class by other mods from firing, which can cause issues such as missing inspector tabs. This mod clears and re-enters instead, preserving the full method execution chain for maximum compatibility.

Performance Notes

Static restriction lists (apparelRestricted, etc.) are HashSet; Add is idempotent for existing elements and will not accumulate indefinitely
ThoughtSettings.CanGetThought has an internal canGetThoughtCache, so repeated population does not degrade runtime performance
Each CE edit triggers mesh regeneration (10-100ms brief stutter), identical to CE's inherent behavior without this mod
Fully restarting the game re-parses all instance fields from XML, restoring initial state
Load Order Place after HAR and Character Editor.