Trying to implement simple function that returns value of an array element like if array was looped, for example if I ask for an element that is 5 positions after the 7th in array of 10 elements in total, it should return the second one, etc.
Want to make it working with different types, so I could pass any array in it, but having the next issue: if I copy an element to output parameter, It gives me a garbage or smth in BP, like if I was dereferencing wrong address.
Tell me please, how do I copy value of UProperty? Also, for some reason I can’t use FProperty, module won’t build if I do that, at the same time UProperty macro works fine… would be nice if someone can explain to me this moment too.
Here is .h
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CppUtils.generated.h"
/**
*
*/
UCLASS()
class PRISMATTER_API UCppUtils : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintPure, meta = (CompactNodeTitle = "Next Looped", ArrayParm = "array", ArrayTypeDependentParams = "item", BlueprintThreadSafe), Category = "Utils")
static void GetNextLoopedArrayElem(const TArray<UProperty*>& array, int nextTo, UProperty*& item, int offset = 1);
};
and .cpp
#include "CppUtils.h"
void UCppUtils::GetNextLoopedArrayElem(const TArray<UProperty*>& array, const int nextTo, UProperty*& item, const int offset)
{
int newIdx = nextTo + offset;
while (newIdx < 0)
{
newIdx += array.Num();
}
newIdx %= array.Num();
item = array[newIdx];
}