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!
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
// 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());
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.
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…
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
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.