Removing Range of data from array

Hi, I’m fairly new to C++ and Unreal, But i do have experience in Unity and C#. I feel im fundamentally not understanding how array’s are passed to a method. I have an array of data coming from an UDP port. I have that working correctly but i need to parse thought the data and organize it. I have created this method to pull data from the array but can’t get it to return the data correctly after i have called the method. The first time it’s called it gives me the right data the second time i call it in a loop it gives me an array of the correct size but all the values of the array are 0.

.h file

TArray GetData(TArray data, int startIndex, int count);

.cpp method

TArray ADataClass::GetData(TArray data, int startIndex, int count) {
	static TArray<uint8> temp;
	temp.SetNum(count);
	for (size_t i = startIndex; i < count; i++)
	{
		temp[i - startIndex] = data[i];
	}
	return temp;
}

This is how im calling the method the get the data.

hs.headerData = GetData(incomingData, 0, 18);

That works when i need to grab it once. When i go to use the imcoingdata array again it give me issue.

I hope this makes sense and somoene can help me out

thanks in advanced

Looks like you aren’t actually getting all your data if count < startIndex

    TArray ADataClass::GetData(TArray data, int startIndex, int count)
    {
        static TArray temp;
        temp.SetNum(count); 
        for (size_t i = startIndex; i < count + startIndex; i++) 
        {
            temp[i - startIndex] = data[i];
        }
        return temp;
    }

Add the startIndex to the count check in your loop to ensure that you get all your data, you’ll also have to check that I does not go outside of the TArray data

THANKS YOU SO MUCH. This fixed my issue. I still don’t think i full understand pointers but that doesn’t seem to be my issue. Thanks again for the help have your self a great day sir