I haven't used C# with Godot a lot, but it seems that the preferred way is to use C# arrays and System.Collections.Generic
classes over Godot.Collections.Array<T>
. That class contains bare minimum for interfacing with the engine and you should use something like List<T>
(generally good and versatile) or Queue<T>
(optimal for push_back
,pop_front
style usage) if you don't need to have array exported or used by gdscript.
This is untested, but should work (on 3.x):
static public T PopFront<T>(ref Godot.Collections.Array<T> array)
{
T firstElement = array[0];
T[] newArray = new T[array.Count - 1];
array.CopyTo(newArray, 1);
array = new Godot.Collections.Array<T>(newArray);
return firstElement;
}
It's not very good solution if the array is big since it gets copied twice (unless there's some optimisation wizardry behind the scenes). I don't know if there's differences with Godot 4.