Store Blueprint actor in a TArray C++
I am trying to create an Inventory system in c++ which allows me to store a blueprint derived from a base class of APickup(C++ Class). My problem is I am struggling to find a way to Check if the pickup blueprint is a derivative of APickup. Here is my attempted code.
Does this seem right? I've logged a loop of the array and it does indeed add something to it, but this would just be a pointer to the initial object from my understanding. I have tried a few things but I'm unable to spawn the object from the array that I have created, Any help would be greatly appreciated. Specifically an explanation of how to store the blueprint that is picked up in an array. Thanks in advance.
EDIT: Ok this works but I want to be able to destroy the actor on pickup and respawn it when the player uses my EquipPickup function. If i set the item to be destroyed on pick up after adding it to the array I will be left with a null pointer so really I want to move or copy the actor in to the array so I can bring it in to other levels.
A pointer, by definition, is used to avoid making extraneous copies of an object. If you wanted to store a copy, your array would need to be:
Which would store an entire copy of the object, rather than just a pointer to it. That said, I don't think you really want to destroy the object/store a copy. If I understand you correctly, you just want to hide it after it's been picked up. In which case you could just call
That way you aren't duplicating Actor objects (which is pretty expensive and honestly I'm not sure if that would work), you still only store pointers in your array, and as long as your array is a UPROPERTY then it should all transfer between levels seamlessly.
answered Sep 09 '16 at 05:30 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here