SerializeReferences Sample
A turret whose weapons and their effects are picked in the Inspector, plus assets broken on purpose for you to repair.


The dummy changes color and shrinks as the configured weapons and effects deal damage.
Open it
- Import the sample: Tools → Aspid 🐍 → FastTools → Welcome → Samples → Import on SerializeReferences.
- Open
Scenes/SerializeReferences.unityand enter Play Mode: the primary weapon and the sidearms take turns hitting the dummy, and the Console reports every hit.
Try
Exit Play Mode and select Loadout.


Weapons, a nested burn effect, and modifiers in the Loadout Inspector.
- Pick a class. Open the Primary dropdown: a searchable picker lists every concrete
IWeapon, grouped under Weapons/Melee and Weapons/Ranged by[TypeSelectorDisplay].DebugWeaponis left out withHidden. PickShotgun: its fields appear under the dropdown. - Shared data survives a switch. In Sidearms, set the
Pistol's Damage to37, switch it toShotgunand back: Damage is still37, because both classes declare_damage. - Lists. Press + on Sidearms: the picker opens instead of copying the last element, and the new element gets its own instance. In Play Mode it joins the firing rotation.
- Narrowing. Melee Backup is declared
IWeapon, but[TypeSelector(typeof(IMelee))]offers onlySword. The Weapon field of each Holster slot is narrowed the same way one level down, inside a plain[Serializable]class:[TypeSelector(typeof(IRanged))]offers only ranged weapons. Neither field joins the firing rotation. - Nested references. The
Railgunin Primary has a Charge Effect, a[SerializeReference]of its own with its own dropdown. It holds aBurnEffect, so the dummy catches fire when the railgun hits. - Abstract base. On Hit is a
StatusEffect: the picker offersBurnEffectandFreezeEffect, never the abstract class. - Generics.
- Damage Modifier is a
Modifier<float>:DamageModifierandModifier<Single>are offered and created at once. - Perks is a
List<IModifier>: besides the closed subclasses it offers the openModifier<T>, which asks forTon a second page. - Only
DamageModifierchanges the damage; Loadout → Log Loadout in the component's context menu prints the values of the others.
- Damage Modifier is a
- Required field. Set Primary to
<None>: a notice appears under the field. Save the scene, and Project References → Scan Project and CI runs with-srGateRequiredreport the field as a violation; a player build does not check it (what each run checks). - Header menu. Right-click a field header for copy and paste, templates, usages and a new script: every item.
Repair
The assets in Presets/ and Prefabs/ store types that are missing or out of date.
- Fix one asset. Select
Presets/BrokenWeaponPreset.asset: Weapon stores aGhostWeaponthat does not exist, and the Missing type notice under the field offers Fix. Press it and pickPistol: Damage25and Magazine Size8are kept. - Fix a group. Open Tools → Aspid 🐍 → FastTools → Project References and press Scan Project: the three
GhostWeaponentries ofBrokenArsenalPreset.assetform one group, and Fix all repairs them at once. - A suggested class.
Presets/MovedWeaponPreset.assetstoresPistolunder an old namespace. Its notice offers → Pistol, and its group in Project References offers Smart Fix → Pistol; neither applies itself. - A migration.
Presets/RenamedWeaponPreset.assetstoresCrossbowLauncher, and the class is nowCrossbowwith[MovedFrom]: the Inspector already showsCrossbow, only the file is out of date. Migrate all → Crossbow in Project References writes the new name into the file. - A prefab. Select
Prefabs/BrokenLoadout.prefabin the Project window.Sidearms[2]is a missingGhostCrossbowwith Fix;Sidearms[0]and[1]point at onePistoland are marked Shared reference #N, and Make unique gives an element its own copy. The Asset References tab lists every reference of the prefab.
To repeat the repair, import the sample again and overwrite its files.
IMGUI inspector
WeaponPreset has an IMGUI inspector, Scripts/Editor/WeaponPresetEditor.cs: plain EditorGUILayout.PropertyField() calls draw the field and the list, with the picker, Fix and the list's + working as in UI Toolkit. For fields without [TypeSelector], see Custom inspector.
Where to look
| File | Shows |
|---|---|
Scripts/Loadout.cs | Every field shape: single, list, narrowed, container, abstract base, closed and open generics, Required |
Scripts/Weapons/ | The IWeapon hierarchy, [TypeSelectorDisplay] groups, a Hidden class, [MovedFrom] on Crossbow, a nested reference in Railgun |
Scripts/Effects/, Scripts/Modifiers/ | An abstract base and an open generic class |
Scripts/WeaponPreset.cs, Presets/, Prefabs/ | The repair scenarios |
Scripts/Editor/WeaponPresetEditor.cs | An IMGUI inspector of plain PropertyField calls |
Reference: SerializeReference Selector and SerializeReference Tooling.