[answered] How to convert pointer to UStruct to UStruct?

I have the following code:

FBaseItem* ItemToAdd = ItemTable->FindRow<FBaseItem>(ItemID, "");
...
InventoryArray.Add(ItemToAdd);

It produces this error while compiling:

error C2664: 'int32 TArray<FBaseItem,FDefaultAllocator>::Add(const FBaseItem &)': cannot convert argument from 'FBaseItem *' to 'FBaseItem &&'
note: Reason: cannot convert from 'FBaseItem *' to 'FBaseItem'
note: No constructor could take the source type, or constructor overload resolution was ambiguous

How would I convert the pointer to a normal struct, other than creating a new struct and copy all the variables?

Hey,
just dereference the pointer, it will make a copy of the struct for you and you can use it

 FBaseItem* ItemToAdd = ItemTable->FindRow<FBaseItem>(ItemID, "");

 InventoryArray.Add(*(ItemToAdd)); // from FBaseItem*  to FBaseItem

Have a good day !

2 Likes

Yeah, that worked.
Thanks a lot.