Download

Static Array

I’m trying to initialize a TStaticArray using this

Simple example:

TStaticArray<int, 2> Arr = { 0, 1 };

However this can’t be done unlike TArray or normal arrays, any thoughts ? I took a look at the implementation or TStaticArray it might be because the array declaration is private perhaps.

I know I can set each element one by one or do a loop but I’m just wondering.

Thank you.

Your question is why can’t you use the standard c++ array’s initializer in your code. The question is inside the declaration of the class. You can check yourself, but i’ll give you this little hint. As you can see in the screenshot below, the TArray class has a constructor which allows the std c++ array initializer signature to be used whenever needed, as in the example. The TStaticArray class does not have such a constructor declaration, so this is the primal reason. Hope this clear your doubts.
Screenshot 2021-09-15 110828

Thanks for the answer, the constructor with the initializer_list makes it possible with TArray as you stated.

I would say TStaticArray is the std::array version of unreal, looking at std::array it doesn’t have a constructor with initializer_list instead it has the array member being public which makes it possible to construct an array using initializer_list implicitly just like you would with a normal array using int[2] Arr = {0, 1};

Thank you again.