Blueprint array add works quite different than C++

It seems when I try to add a inventory item to a array on my character it only adds that item once and its more of like a reference of that item in the world. Where as in cpp

TArray<Item*> myInventory; myInventory.Add(someitem*); 

adds a clone of the item then its up to me to dispose of the item.

(my Item is called BP_ItemFood, and is derived from BP_Item, my array holds bp_items) .

How do I get it to work like cpp more? Because when i try to add a item to my inventory and then destroy the item, it actually destroys it in my inventory also, and gives a error that says pending kill.

In cpp i did not have this problem. It actually cloned the item and threw it into the array and it was my job to dispose of the phyiscal reference in the world. In blueprint it seems like its just adding the physical reference of the item to the array but its info is still stored on the object in the world.

I guess I could just hide the object in the world but I don’t really want to do this.

C++ and blueprint arrays of actor references work the same way. they both store pointers to actors that are spawned into the world.
if you want to reference an actor, it has to be spawned into the world and exist for the entire time you need to use that pointer. if you want to save memory, and you don’t need to see the actor, you could instead store an array of structs that contain enough data to spawn the actor when you actually need it to exist.

i don’t recognize the syntax in your c++ example.
why do you have an asterisk after someitem*? are you trying to dereference a pointer? because if you want to dereference a pointer, the asterisk should be before *someitem, but dereferencing a pointer would give you the literal value it pointed to, which doesn’t make sense to add to an array of pointers, because its not a pointer. i would be surprised if that code compiles at all, since i have never seen an asterisk after a class without being followed by a name, and it takes 2 parameters to be considered multiplication, so it looks like gibberish to me.
is it a typo maybe?

is this what you meant?:

TArray<AItem*> myInventory;

FActorSpawnParameters SpawnInfo;
AItem* someItem = GetWorld()->SpawnActor<AItem>( GetClass(), SpawnInfo );
someItem->Ammo = 20;
myInventory.Add(someItem);

if ( myInventory[0] )
{
    myInventory[0]->Ammo--;
}

Yeah it was a typo because i was doing it from memory, I’m using blueprints now. But like I said how do i make a clone of the item i want to pick up and add that to the array then destroy the item in the world. Then respawn the item when I drop it. All in blueprints . If i add the item to the array and then destroy the item in the world its no longer in my inventory array. Where as in C++ it makes a clone. Actually in C++ maybe it wasnt making a clone, but since before when i was doing C++ i was deriving blueprints off my c++ class and the blueprint was able to be destroyed but un-noticed to me the object of the c++ class was probably still in the world.

if you want to clone an actor, you have to spawn a new actor, and copy over all of the properties from the old actor. then you can destroy the old actor. but that doesn’t really help you achieve anything.

it would be better to store a struct that contains similar variables to your actor, and when you need to drop the actor into the world, you just spawnActorFromClass, then copy over its properties from the struct you stored in your inventory. then you can delete the struct from the inventory. the array of structs should not be pointers to structs, but actual structs.