ComponentTypeSelector
Change a component's class right in the Inspector while shared fields keep their values.
Quick start
public abstract class EnemyBase : MonoBehaviour
{
[SerializeField] private ComponentTypeSelector _enemyType;
[SerializeField] private float _health = 100f;
}
| FastEnemy.cs | ArmoredEnemy.cs |
|---|---|
| |
The list offers the class that declares the field, unless it is abstract, and its concrete subclasses, with no <None> entry. Display settings from [TypeSelectorDisplay] apply here, while [TypeSelector] does not configure the list.


| Field | FastEnemy | ArmoredEnemy picked | Back to FastEnemy |
|---|---|---|---|
| Health | 75 | 75 | 75 |
| Speed | 40 | — | 25 |
| Armor | — | 10 | — |
When the type does not change
The switch follows the rules of Add Component: the components the new class lists in [RequireComponent] are added with it. The class stays as it was, and the Console shows why, when:
- Unity would refuse to add the new class or remove the old one;
- the class has no script file of its own with the same name, such as a nested class;
- the component is inherited from a prefab (an instance in a scene or a variant): change its class in the source prefab.
With several components selected, a refusal for one of them leaves all of them as they were.
Package sample
The Types sample shows component type switching.

