Getting Data From FArrayProperty

Hey everyone, I am currently trying to get the value of variables from a Blueprint inside C++. So far, I can do that easily with numeric values using the following code:

auto NumericVariable = CastField<FNumericProperty>(WorldContextObject->GetClass()->FindPropertyByName(VariableName));
if(NumericVariable)
{
	auto NumericValue = NumericVariable->GetFloatingPointPropertyValue(NumericVariable->ContainerPtrToValuePtr<void>(WorldContextObject));
	GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, VariableName.ToString() + FString::SanitizeFloat(NumericValue));
}

However, for my use case, I would also need to get the values in a Vector2D. As there is no property type for it, I thought a way around that was to turn it into a 2-element array representing x and y. The issue I am currently facing is not being able to extract the data inside an FArrayProperty. The following is what I tried:

auto ArrayVariable = CastField<FArrayProperty>(WorldContextObject->GetClass()->FindPropertyByName(VariableName));
if(ArrayVariable)
{
	auto ArrayValue = ArrayVariable->GetPropertyValue(ArrayVariable->ContainerPtrToValuePtr<void>(WorldContextObject));
}

This gets me a FArrayProperty::TCppType data type for ArrayValue. The issue is trying to use ArrayValue.GetData() returns a void pointer. I tried casting and printing the value with the following code:

auto ArrayDouble = Cast<TArray<double>>(ArrayValue.GetData());
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, SeriesName.ToString() +FString::SanitizeFloat(*ArrayDouble[0].GetData()));

This gives me a cast error, switching to reinterpret_cast<TArray<double>*> solved it and now the code compiles, but then gives me the following runtime error:

Assertion failed: false [File:D:\EpicGames\UE_4.27\Engine\Source\Runtime\Core\Public\Containers/ScriptArray.h] [Line: 242] 

After doing some debugging, I found that the error was caused by using GetPropertyValue. Switching to GetPropertyValuePtr solved it, but then ArrayValue becomes a const FScriptArray* which does not seem to work with Cast, const_cast, or reinterpret_cast.

I know that the data inside ArrayValue is valid because when printing ArrayValue->Num(), I get the correct number of elements of the Blueprints variable and it also dynamic changes as the number of elements shrinks and grows. I just do not know how to get the actual data inside C++.

Is there any other way that I am missing to get the data? Also, did I miss a way to get a Vector2D variable directly? Any help would be greatly appreciated and I apologize for the long post.

Update I managed to fix this by removing TArray from the cast and using static_cast, here’s the fixed code:

auto ArrayVariable = CastField<FArrayProperty>(WorldContextObject->GetClass()->FindPropertyByName(SeriesName));
if(ArrayVariable)
{
	auto ArrayValue = ArrayVariable->GetPropertyValuePtr(ArrayVariable->ContainerPtrToValuePtr<void>(WorldContextObject));
	auto ArrayDouble = static_cast<const float*>(ArrayValue->GetData());
}