So hey, to keep things short
Im sort of stumped, Trying to create a basic item system ( Pick up physical items in the world that get added to the player inventory etc )
i got the basics working fine, I can pick up items from the world and they are stored in the player inventory, Now the MAIN issue comes when it comes to calling functions in the items from the
inventory array, Im trying to use a blueprint to handle item actions ( Using,Dropping etc ) so i wouldnt need to manage it trough c++, So for this i created a event that i can use in my item blueprint
thats called when said item is used
IF i dont call Destroy() on the physical item the event works fine, if i destroy the item in the world and call the event from the item in the inventory array the blueprint doesnt work… Here is the code im using to pick up the items and add them to the world
ACharacter Header
#pragma once
#include "ProojectCharacter.generated.h"
class AProojectItem;
UCLASS(config=Game)
class AProojectCharacter : public ACharacter
{
GENERATED_UCLASS_BODY()
/** items inventory */
UPROPERTY(EditAnywhere, Category = Inventory)
TArray<class AProojectItem*> ItemInventory;
void PickUpItem(AProojectItem* Item);
ACharacter.cpp
void AProojectCharacter::PickUpItem(AProojectItem* Item)
{
if (Item)
{
Inventory.Add(Item);
Item->BeginDestroy(); // Item is in inventory now
ItemInventory[0]->Used(); // Only works if i dont call destroy
}
}
I know i can instead of destroying the class just hide its graphical components but what if i have 999 items in the world ( just an example number) Even if their visible elements such as static mesh and collision are disabled i still have all of these instances in the world it seems kinda wrong to just leave them there instead of keeping them only in the Inventory array