How do I pass a Tarray in a BlueprintImplementableEvent?

I want to dispatch this event in several cases and handle all of them in same node and its connecting logic. Works fine for primitives like float but for a tarray of a struct (stack of inventory items), it screams this error.

UFUNCTION(exec, BlueprintImplementableEvent, Category = "ServerManager")
virtual void OnItemsUpdate(TArray<FItemStack> ItemList);

Error	1	error C2511: 'void AServerManager::OnItemsUpdate(const TArray<FItemStack,FDefaultAllocator> &)' : overloaded member function not found in 'AServerManager'	D:\UE4\Prototype\Intermediate\Build\Win64\Inc\Prototype\Prototype.generated.cpp	205
Error	2	error C2352: 'UObject::FindFunctionChecked' : illegal call of non-static member function	D:\UE4\Prototype\Intermediate\Build\Win64\Inc\Prototype\Prototype.generated.cpp	208

And

USTRUCT(BlueprintType)
struct PROTOTYPE_API FItemStack
{
	GENERATED_USTRUCT_BODY()

In case it mattered what that type was.

Any ideas what I am doing wrong? Thanks in advance!

You should have your tarray as a const with a & at the end, something like this:

MyFunction(const TArray<AActor*>& VarName)
5 Likes

Could you briefly explain why this needs to be done? Or direct me to an article or something that explains it? Thanks

Error C2511 is returned when you try to implement a function that does not exist (a very basic example can be found at c++ - VS2010 overloaded member function not found - Stack Overflow). Somewhere in your code you have an implementation of the function

    void AServerManager::OnItemsUpdate(const TArray<FItemStack,FDefaultAllocator> &)

Which does not exist. The virtual function you need to implement is

    virtual void OnItemsUpdate(TArray<FItemStack> ItemList)

I cant tell much because not much info on your declarations and implementations has been posted but changing your implementation line to this should fix it

    void AServerManager::OnItemsUpdate(TArray<FItemStack> ItemList)

The 2 differences are

  1. virtual function does not have want a “const TArray”
  2. virtual function takes an object not a reference (&)

To save any confusion, your implementation line will not actually have

    TArray<FItemStack,FDefaultAllocator> 

it will have

    TArray<FItemStack>

The FDefaultAllocator is something that would be added by the C++ compiler

As for error C2352, i cant tell what is happening here because i dont know what FindFunctionChecked is supposed to do and how you are trying to call it

Hope this helps

as Wilson89 explains below, the source of the problem is that the signatures in the header and the cpp do not match. But somehow with tarrays even though I made sure they matched, this error pops up sometimes, because the compiler seems to see it as a const & type in the header, and you only have the simple type (pass by value) in your implementation, so in my case this problem was solved when I used const & both in header and in cpp. (I tried different types - pass by value, reference, const reference, but I think only const reference worked)

Something similar can be found here:

https://answers.unrealengine.com/questions/95396/fail-to-pass-tarray-from-c-to-blueprint.html