Godot Version
4.2
Question
I have an example that works great.
public partial class DropMenu : Button
{
private object[] _items;
public void Init<T>(T startItem ) where T : Enum
{
var items = Arithmetic.GetEnumerableEnum<T>().ToArray();
_items = items.Cast<object>().ToArray();
_index = Array.IndexOf(items, startItem);
}
}
example of receiving
GetNode<DropMenu >("....")
But when I use “T” I get an error
public partial class DropMenu<T> : Button where T : Enum
{
private int _index, _oldIndex;
private T[] _items = Arithmetic.GetEnumerableEnum<T>().ToArray();
public void Init(T startItem)
{
_index = Array.IndexOf(_items, startItem);
}
}
I get an error this
GetNode<DropMenu<тSomeEnum>>("....")
question - is there a way to solve this problem? or should I just put up with it and write “shit code”?
object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void*, object): System.InvalidCastException: Unable to cast object of type ‘Godot.Button’ to type ‘DropMenu`1[Mygame.Scripts.GameLogic.World.Base.BaseRoom+ThisType]’.
<Ошибка C++> System.InvalidCastException