Skip to main content

Types Sample

A spawner whose enemy type and wave pattern are picked in the Inspector, without touching code.

A wave of regular and elite enemies moves toward the center.A wave of regular and elite enemies moves toward the center.

A wave of regular and elite enemies moves toward the center.

Open it​

  1. Import the sample: Tools → Aspid 🐍 → FastTools → Welcome → Samples → Import on Types.
  2. Open Scenes/Types.unity and enter Play Mode: every six seconds eight enemies appear in a circle, every fourth one an ArmoredGrunt, and walk to the center.

Try​

Exit Play Mode and select Enemy Spawner.

Enemy types and spawn pattern in the Inspector.Enemy types and spawn pattern in the Inspector.

Enemy types and spawn pattern in the Inspector.

  1. A component type that survives a rename. Enemy Type is a SerializableMonoScript<Enemy>: along with the class name, the field keeps a reference to the script asset. Rename the class in Scripts/Enemies/Grunt.cs to Footman, together with the file and its .meta, so that the derived ArmoredGrunt is updated too. After the recompile the field reads Footman; a SerializableType in its place would show <Missing …>.
  2. A dependent picker. Elite Type is a string with [TypeSelector(nameof(_enemyType))]: its picker offers only the class in Enemy Type and its subclasses. Switch Enemy Type to Archer and open Elite Type: Archer and Sniper are offered, ArmoredGrunt is not. The field keeps ArmoredGrunt until you pick another type, so pick Sniper.
  3. Names, groups and icons. Open Pattern: the patterns sit in one Spawn Patterns group, each with its own name, tooltip and icon from [TypeSelectorDisplay]. OriginPattern is hidden with Hidden, and Allow = TypeAllow.None on the field leaves out the ISpawnPattern interface itself. Pick Grid and enter Play Mode: the waves line up in a grid.
  4. A required field. Set Enemy Type to <None>: a notice appears under the field. Save the scene, and Project References → Scan Project and CI runs with -srGateRequired report the field as a violation; a player build does not check it (what each run checks).
  5. Swap a component in place. Select Placed Enemy (swap its type) and set Health to 250. The dropdown at the top of its Inspector is the ComponentTypeSelector field of Enemy. Switch Archer to Brute: Health and Speed, declared on the shared base, keep their values, and Keep Distance, which only Archer has, is gone.

Where to look​

FileShows
Scripts/EnemySpawner.csSerializableMonoScript<T> with Required, [TypeSelector] referencing another field, SerializableType<T> with Allow = TypeAllow.None, reading each type through .Type and Type.GetType()
Scripts/Enemies/Enemy.csThe ComponentTypeSelector field on the base class; subclasses in the same folder
Scripts/Spawning/The ISpawnPattern interface and plain C# patterns with [TypeSelectorDisplay]

Reference: Serializable Type System and ComponentTypeSelector. See also the SerializeReferences sample for [TypeSelector] on [SerializeReference] fields and the EditorTools sample for the same picker opened from editor code.