После нескольких часов борьбы с неприятной ошибкой мне удалось все разбить на одну вещь, которую я не могу понять.
У меня есть персонаж gameObject, в котором есть 2 компонента.
1) StateSwitcher (класс, использующий принцип фабричного проектирования: он возвращает состояния в зависимости от определенных условий символа)
2) General State (класс, от которого наследуются все состояния, который содержит данные общего состояния и поведение
Мой инспектор персонажей выглядит так:

Как видите, я назначил StateSwitcher для GeneralState, просто выбрав его в представлении инспектора.
Вот как выглядит GeneralState.cs:
// This class contains all fields, properties & methods shared across all states
public class GeneralState : MonoBehaviour
{
private void Start()
{
Debug.Log(StateSwitcher);
}
}
Вот что меня смущает:

изменить 1:
// This class contains all fields, properties & methods shared across all states
public class GeneralState : MonoBehaviour
{
private void Start()
{
Debug.Log(StateSwitcher.GetInstanceID());
}
}
Результаты в этом:

изменить 2:
// This class contains all fields, properties & methods shared across all states
public class GeneralState : MonoBehaviour
{
private void Start()
{
Debug.Log(this.GetInstanceID());
}
}
результатов в этом:
