I need to remove some data from an array (the data is in sequence). So I like to have an Array::RemoveAt function that takes in a count of objects to remove.
Writing a standard UFUNCTION like
UFUNCTION(BlueprintCallable,...)
static void RemoveAtRange(TArray<int32>& Array, const int32 Index, const int32 Count);
within a library does not work at this point as it would fix the array element type (in this case to int32).
Having a look at Unreal implementation for generic array functions, we get:
KismetArrayLibrary.h
A UFUNCTION that creates the Blueprint node, but is not executed (note the UFUNCTION(…, CustomThunk,…)
/*
*Remove item at the given index from the array.
*
*@param TargetArray The array to remove from
*@param IndexToRemove The index into the array to remove from
*/
UFUNCTION(BlueprintCallable, CustomThunk, meta=(DisplayName = "Remove Index", CompactNodeTitle = "REMOVE INDEX", ArrayParm = "TargetArray"), Category="Utilities|Array")
static void Array_Remove(const TArray<int32>& TargetArray, int32 IndexToRemove)
{
check(0); // should never execute
}
The actual function beeing executed by the CustomThunk (below) that does the removal and error checks
static void GenericArray_Remove(void* TargetArray, const UArrayProperty* ArrayProp, int32 IndexToRemove);
And the user generated CustomThunk that operates on the StackFrame (FFrame in Stack.h)
DECLARE_FUNCTION(execArray_Remove)
{
Stack.MostRecentProperty = nullptr;
Stack.StepCompiledIn<UArrayProperty>(NULL);
void* ArrayAddr = Stack.MostRecentPropertyAddress;
UArrayProperty* ArrayProperty = Cast<UArrayProperty>(Stack.MostRecentProperty);
if (!ArrayProperty)
{
Stack.bArrayContextFailed = true;
return;
}
P_GET_PROPERTY(UIntProperty, Index);
P_FINISH;
P_NATIVE_BEGIN;
GenericArray_Remove(ArrayAddr, ArrayProperty, Index);
P_NATIVE_END;
}
My issue is the CustomThunk. There are also more complex CustomThunks for basically every other generic array function. Can anybody give some insight about those and the operations on the Stack?