# Get Length of Array of Struct Arrays

**URL:** <https://forums.unrealengine.com/t/get-length-of-array-of-struct-arrays/541963>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [April 28, 2022, 12:51pm UTC](https://forums.unrealengine.com/t/get-length-of-array-of-struct-arrays/541963 "2022-04-28T12:51:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Heigl\_KFP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/heigl_kfp/32/250867_2.png) [@Heigl\_KFP](https://forums.unrealengine.com/u/Heigl_KFP)\
**Post date:** [April 28, 2022, 12:51pm UTC](https://forums.unrealengine.com/t/get-length-of-array-of-struct-arrays/541963/1 "2022-04-28T12:51:53Z")

</div>

Hi All,

I need to build, and then sort, an integer array.  
What I have is an array of nested arrays. I want to add the length of each nested array to the int array, but the following error occurs:  
E0135 class “FOPTPLacementArray” has no member “Num”

I couldn’t find a solution, any help is appreciated!

> **The Structures**
>
> USTRUCT(BlueprintType)  
> struct FOPTPlacement  
> {  
> GENERATED\_BODY()
> 
> ```
> UPROPERTY(BlueprintReadWrite)
> UGridPanel* GridPanel;
> 
> UPROPERTY(BlueprintReadWrite)
> bool Column;
> 
> UPROPERTY(BlueprintReadWrite)
> int Index;
> 
> UPROPERTY(BlueprintReadWrite)
> float Length;
> 
> ```
> 
> };
> 
> USTRUCT(BlueprintType)  
> struct FOPTPLacementArray  
> {  
> GENERATED\_BODY()
> 
> ```
> UPROPERTY(BlueprintReadWrite)
> TArray<FOPTPlacement> OPTPlacements;
> 
> ```
> 
> };

> **The Code in the .cpp file**
>
> ```
> TArray<int> LengthArray;
> 
> for (auto& elem : ArrayOfOPTPlacements)
> {
> LengthArray.Add(elem.Num());
> 
> };
> 
> ```

---

<div class="post-metadata">

**Author:** ![Heigl\_KFP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/heigl_kfp/32/250867_2.png) [@Heigl\_KFP](https://forums.unrealengine.com/u/Heigl_KFP)\
**Post date:** [April 28, 2022, 2:44pm UTC](https://forums.unrealengine.com/t/get-length-of-array-of-struct-arrays/541963/3 "2022-04-28T14:44:43Z")

</div>

Thanks a lot for the reply. Unfortunately, your approach gives me the following three errors:

| Error Code | Description |
| --- | --- |
| C2039 | ‘Num’: is not a member of ‘FOPTPLacementArray’ |
| C2819 | type ‘FOPTPLacementArray’ does not have an overloaded member ‘operator -\>’ |
| E3364 | operator → or -\>\* applied to const FOPTPLacementArray instead of to a pointer type |

In the Source Code, Unreal is using .Num() preferably. The issue is that I have to link the “array element” to the “TArray” it solely consists of…

---

<div class="post-metadata">

**Author:** ![Ares9323](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ares9323/32/1194521_2.png) [@Ares9323](https://forums.unrealengine.com/u/Ares9323)\
**Post date:** [April 28, 2022, 4:00pm UTC](https://forums.unrealengine.com/t/get-length-of-array-of-struct-arrays/541963/5 "2022-04-28T16:00:19Z")

</div>

I think I solved the mistery:

> **.h File**
>
> ```auto
> USTRUCT(BlueprintType)
> struct FOptPlacement
> {
> GENERATED_BODY()
> 
> UPROPERTY(BlueprintReadWrite)
> bool Column;
> 
> UPROPERTY(BlueprintReadWrite)
> int Index;
> 
> UPROPERTY(BlueprintReadWrite)
> float Length;
> 
> // Constructor, only for debug purpose
> FOptPlacement()
> {
> Column = false;
> Index = 0;
> Length = 0.0f;
> }
> };
> 
> USTRUCT(BlueprintType)
> struct FOptPlacementArray
> {
> GENERATED_BODY()
> 
> UPROPERTY(BlueprintReadWrite)
> TArray<FOptPlacement> OptPlacementsArray =
> {
> // Adding three values, only for debug purpose
> FOptPlacement(),
> FOptPlacement(),
> FOptPlacement()
> };
> };
> 
> ```

> **.cpp File**
>
> ```auto
> // This must be be inside a function
> TArray<int> LengthArray;
> FOptPlacementArray OptPlacementsArray;
> 
> for(auto Element : OptPlacementsArray.OptPlacementsArray)
> {
> LengthArray.Add(Element.Length);
> };
> 
> // Should log a red 3 in the output log	
> UE_LOG(LogTemp, Error, TEXT("%d"), LengthArray.Num());
> 
> ```
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/3/7/037609241f5f903003d6fb75ce14c18647c1af98.png)

---

<div class="post-metadata">

**Author:** ![Heigl\_KFP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/heigl_kfp/32/250867_2.png) [@Heigl\_KFP](https://forums.unrealengine.com/u/Heigl_KFP)\
**Post date:** [April 28, 2022, 4:32pm UTC](https://forums.unrealengine.com/t/get-length-of-array-of-struct-arrays/541963/6 "2022-04-28T16:32:26Z")

</div>

Thanks really much for the time you are taking for me, it is much appreciated!!

I see what you did here, my sincere apologies, I forgot to clarify. The Struct contains a var “Length” for me to determine the optimal placement later on. The “Length” I was referring to was the number of array elements inside the array of arrays.

But your approach might not be that far off. In BP I have to “split” the array element to get access to the nested array. I need to incorporate this “split” action in c++ and this might be through the 3rd line of your code.

```auto
FOptPlacementArray OptPlacementsArray;

```

I need to show the code that the n-th element of the “FOPTPLacementArray” is an array of type “FOPTPlacement” which I am relatively sure, it doesn’t know right now…

---

<div class="post-metadata">

**Author:** ![Ares9323](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ares9323/32/1194521_2.png) [@Ares9323](https://forums.unrealengine.com/u/Ares9323)\
**Post date:** [April 28, 2022, 4:35pm UTC](https://forums.unrealengine.com/t/get-length-of-array-of-struct-arrays/541963/7 "2022-04-28T16:35:35Z")

</div>

> [@Heigl\_KFP](#):
>
> The Struct contains a var “Length” for me

Ooops. I didn’t notice it because I didn’t write it 😅  
I trusted Git Copilot too much and I didn’t read the struct variable names 🤣🤣

I’ll try again because I’m curious to sort this out

---

<div class="post-metadata">

**Author:** ![Ares9323](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ares9323/32/1194521_2.png) [@Ares9323](https://forums.unrealengine.com/u/Ares9323)\
**Post date:** [April 28, 2022, 4:51pm UTC](https://forums.unrealengine.com/t/get-length-of-array-of-struct-arrays/541963/8 "2022-04-28T16:51:36Z")

</div>

I think I am missing something:

We obviously can’t get the .Num() of the Element, because it is not an array!

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/9/a/f9aee31b093974ce0b304fa35e58ae81522d6163.png)

Can you please explain again what do you need to obtain?

---

<div class="post-metadata">

**Author:** ![Heigl\_KFP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/heigl_kfp/32/250867_2.png) [@Heigl\_KFP](https://forums.unrealengine.com/u/Heigl_KFP)\
**Post date:** [April 28, 2022, 5:02pm UTC](https://forums.unrealengine.com/t/get-length-of-array-of-struct-arrays/541963/9 "2022-04-28T17:02:33Z")

</div>

> [@Ares9323](#):
>
> because it is not an array!

It is! But the code doesn’t recognize it as such xDD

“FOPTPLacementArray” contains Arrays of “FOPTPlacement”. But if we run a for each loop, it will get the n-th element of the “FOPTPLacementArray” which is a struct. But the only member of this struct is an array of “FOPTPlacement”.  
Theoretically, if I take elem[0] it should give me that array, but

> E0349 no operator “” matches these operands

I am currently trying to do:

> TArray"\<“FOPTPlacement”\>" elem2 = elem;

but it doesn’t know how to convert…

---

<div class="post-metadata">

**Author:** ![Heigl\_KFP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/heigl_kfp/32/250867_2.png) [@Heigl\_KFP](https://forums.unrealengine.com/u/Heigl_KFP)\
**Post date:** [April 28, 2022, 5:05pm UTC](https://forums.unrealengine.com/t/get-length-of-array-of-struct-arrays/541963/10 "2022-04-28T17:05:53Z")

</div>

Solved it LOL. Instead of trying to access the 0th element of the struct, just access the struct property directly and place it into a new variable with matching type. Then, I can get the .Num() from the new variable.

```
for (auto& elem : ArrayOfOPTPlacements)
{
	TArray<FOPTPlacement> elem2 = elem.OPTPlacements;
	LengthArray.Add(elem2.Num());

};

```

@Ares9323 I appreciate your help very very much!
