Are there build in functions to add new element to TArray and remove last?

#include “Runtime/Core/Public/Containers/Queue.h” TQueue<int> would do it for you. But it wont work as UPROPERTY and it is designed to be thread safe so it likely has significant overhead if you don’t need that.

Alternatively you could wrap TArray for a faster offset based approach:



namespace IndexArray {
    template<typename T, typename Allocator, typename ZeroInt>
    FORCEINLINE bool PushSwap(T & Item, TArray<T, Allocator> &Arr, ZeroInt &Zero) const {
        const int32 Size = Arr.Num();

        if (!Size) {
            return false;
        }

        if (++Zero >= (ZeroInt)Size) {
            Zero %= (ZeroInt)Size;
        }

        T&At = Arr(int32)Zero];

        T Swap = std::move(Item);
        Item = std::move(At);
        At = std::move(Swap);
    }

    template<typename T, typename Allocator, typename ZeroInt>
    FORCEINLINE int32 Add(const T & Item, TArray<T, Allocator> &Arr, ZeroInt &Zero){
        const int32 Size = Arr.Num();
        if (!Size)
        {
            Zero = Arr.Add(Item);
            return 0;
        }
        else if (Size <= Zero)
        {
            Zero %= Size;
        }
        Arr.Insert(Item, Zero++);
        return Size;
    }
};
USTRUCT()
struct FIntQueue {
    GENERATED_BODY();
public:
    UPROPERTY() TArray<int32> Arr;
    UPROPERTY() int32 Zero;

    FORCEINLINE decltype(auto) Num() const { return Arr.Num(); }
    FORCEINLINE decltype(auto) Add(const int32& value) { return IndexArray::template Add<>(value, Arr, Zero); }
    FORCEINLINE decltype(auto) AddRemove(int32& value) { return IndexArray::template PushSwap<>(std::move(value), Arr, Zero); }
    FORCEINLINE decltype(auto) operator ](int32 i)const { return Arr(Zero + i) % Arr.Num()]; }
    FORCEINLINE decltype(auto) operator ](int32 i) { return Arr(Zero + i) % Arr.Num()]; }
};

Have not tested the above code at all, but just giving you an idea of how it would go.