TArray with TFixedAllocator and UPROPERTY fails to compile

This code can’t compile on 4.6.1:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory", Replicated) TArray<FInventoryItemStruct, TFixedAllocator<11>> Items;

It returns the error “In InventoryComponent: Missing ‘>’ in ‘tarray’”.

Removing the UPROPERTY solves the problem (but I need the UPROPERTY).

It may be linked to this issue: https://answers.unrealengine.com/questions/77056/uproperty-tarray-whitespace-compiler-error.html

Sorry, the text was malformated. I corrected to include the types as intended.

you need whitespace between the closing angle brackets to keep them from being recognized as a >> operator.

TArray<FInventoryItemStruct, TFixedAllocator<11> > Items;

Yeah, I tried that, same error. Tried in different places too.

If I remove the UPROPERTY, it removes the error, even with the ‘>>’ without spaces.

C++11 has fixed the ‘double closing angle brackets’ issue, but that is not the problem here. The problem is that properties with a non-default allocator (doesn’t matter which) are not supported right now.

The error message is not helpful; we will fix that. However, you will need to change your code to either not be a UProperty or not have a fixed allocator.

Sorry for all the trouble,

Steve

Thanks!

Can you convert your comment as answer, so that I can mark it the solution?

I’ve improved the error message that you get when providing an allocator to a TArray property. Now it will say:

Found 'TFixedAllocator' - explicit allocators are not supported in TArray properties.

The change can be found on GitHub here:

https://github.com/EpicGames/UnrealEngine/commit/80159c6fcf14ffe304557f86133ec404be48b8ba

Steve

I just ran into this problem while using TInlineAllocator, which I tried to use following this article.

Could you update the above article to include this bit of information?

Thanks,
Sean

Hi Sean,

Sorry for the confusion that you may have been experiencing here. As Steve mentioned, non-default allocators are not supported with TArrays that are exposed to the Editor. I read through the post that you linked and did not see any mention of UPROPERTY being used, so I believe the intention was to provide examples of how to allocate memory for TArrays used in code, and not exposed to the Editor. However, I can see where this could be potentially confusing if you start with the assumption that the TArray is being exposed to the Editor as a UPROPERTY. I will check and see if we can do anything to make this a little more clear.