Keep settings with the right object
The idea in one sentence
A UI position tells you where an object is right now. A stable ID tells you which object it is.
Think of a weapon rack: moving a labeled weapon from the first hook to the second hook does not change which weapon it is. Settings should follow the weapon's label, not remain attached to the hook.
A concrete weapon example
Suppose an R-301 can appear in either loadout slot:
Before swap
R-301, ID 17
Flatline, ID 8
Weapon record 17
After swap
Flatline, ID 8
R-301, ID 17
Still weapon record 17
If you save by primary or secondary, an edit stays attached to that position after the swap and can affect the wrong weapon. If you save by weapon ID, the edit follows the R-301 wherever the UI displays it.
Resolve the position into an identity
Use the selected UI slot only to discover the stable ID. Then calculate storage from that ID:
After a weapon swap, update primary_weapon and secondary_weapon. Do not move or rewrite the saved weapon records merely because their screen positions changed.
Use this pattern beyond weapons
The same rule applies whenever something can move:
Primary, secondary, or sling slot
Weapon ID
Menu row after sorting
Item ID
Player position in a lobby list
Player ID
Preset button
Preset ID
The test is simple: if two objects trade positions, do their saved settings stay with the correct objects? If not, the code is probably using position as identity.
Last updated

