i did it like that. I Think is better and simple too, here the proposed solution doesn't worked in godot 4.3
foreach (var child in GetChildren())
{
if (child is IState) _states.Add(child as IState);
}