Passing a TArray to a BlueprintNativeEvent for Blueprint

Problem:

I’ve got the following BlueprintNativeEvent:

// When the game starts, this method loads the inventory widget with the current inventory items
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Custom")
	void LoadInventoryIntoWidget(TArray<AInventoryItemActor*> InventoryItems);
virtual void LoadInventoryIntoWidget_Implementation(TArray<AInventoryItemActor*> InventoryItems);

And here is the implementation:

void UInventoryUserWidget::LoadInventoryIntoWidget_Implementation(TArray<AInventoryItemActor*> InventoryItems)
{

}

I’m getting the following error when i compile:

...\InventoryUserWidget.gen.cpp(42) : error C2511: 'void UInventoryUserWidget::LoadInventoryIntoWidget(const TArray<AInventoryItemActor
*,FDefaultAllocator> &)': overloaded member function not found in 'UInventoryUserWidget'

If i make the the method take a TArray reference instead, the code compiles but the event is not visible within the editor.

Context:

I need to insert previously picked up inventory items into my inventory widget when the game loads. I am attempting to create a blueprintnativeevent that i can add c++ into while at the same time, implement the visual aspects of the widget through Blueprint.


Where am i going wrong?
Is it even possible to pass blueprint a TArray for an event?

Additional info:

Here is an example of a BlueprintNativeEvent that does work:

header definition:

// When the game starts, this method loads the inventory widget with the current inventory items
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Custom")
	void LoadInventoryIntoWidget(UInventory* Inventory);
virtual void LoadInventoryIntoWidget_Implementation(UInventory* Inventory);

cpp declaration:

void UInventoryUserWidget::LoadInventoryIntoWidget_Implementation(UInventory* Inventory)
{

}

so it seems to be a specific problem with TArray

Thanks for posting! Not sure i follow your answer. I’ve added “Additional Info” to my question to hopefully help clear up any confusion

You don’t need to declare

virtual void LoadInventoryIntoWidget_Implementation(TArray<AInventoryItemActor*> InventoryItems);

It is declared implicitly, you only need to implement it.

You would only need to declare it on any c++ subclasses that want to override the implementation.

Also I would consider making the array a const reference.

I am saying that in your header you don’t need the _Implementation declaration, just the declaration of the event. Not sure what effect that is having and if it’s the source of the problem, but you shouldn’t need to declare it explicitly, it is declared in the auto-generated header.

Same issue unfortunately. Without implementation duplicates in the header: Thanks for trying though! “overloaded member function not found”. And if i change to const ref, it doesn’t appear in blueprint… As soon as i remove the TArray part, it shows up again.

Also, it seems that my intellisense is getting confused and showing my cpp implementations as errors even though it compiles. If i add the _implementation back into the header, the intellisense is happier. Perhaps that’s why i started doing that in the first place. Less confusing i guess.

Yes, they usually show as errors for me as well. Sometimes they go away, sometimes they come back. I find Intellisense to be generally useless for UE4 development.

Okay. Good to know.

Oh! Actually. That is now showing with const TArray& !!! Yehaa. I guess it didn’t update the dll first time around… Sweet, thanks dude! Also… my intellisense errors are still there, do they also show as errors on yours? I’m on VS2019.