Hi DennyR , sorry to bother you again. I am studying what can i do and I realise that i didn’t understand why i shood encapsulating the ItemClasses.
I will explain what i have:
An ItemDataBase
USTRUCT()
struct FItemData
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditDefaultsOnly, Category = Item)
TSubclassOf<class AItem> Item;
//Other info that I could need
};
/**
*
*/
UCLASS()
class My_API AItemDataBase : public AActor
{
GENERATED_UCLASS_BODY()
UPROPERTY(EditDefaultsOnly, Category = ItemDatabase)
TArray<FItemData> ItemClasses;
TSubclassOf<class AItem> GetItemByName(FString ItemName);
TSubclassOf<class AItem> GetItemById(int32 index);
};
And a child blueprint “BPItemDataBase” where i fill with data the TArray “ItemClasses”.
On a “InventoryManager” constructor i just instantiate the Data Base
static ConstructorHelpers::FObjectFinder<UBlueprint> ItemBDBlueprint(TEXT("Blueprint'/Game/Blueprints/Inventory/BPItemDataBase.BPItemDataBase'"));
if (ItemBDBlueprint.Succeeded())
{
GameItemDataBase = (UClass*)ItemBDBlueprint.Object->GeneratedClass;
ItemDB = GameItemDataBase->GetDefaultObject<AItemDataBase>();
}
And on my GameMode in the BeginPlay function i Spawn the InventoryManager:
void AMyGameMode::BeginPlay(){
Super::BeginPlay();
InventoryManager = Cast<AInventoryManager>(GetWorld()->SpawnActor(AInventoryManager::StaticClass()));
}
Then i have a ContainerLoot class, with can hold loot woth a TArray:
UPROPERTY(EditDefaultsonly, BlueprintReadOnly, Category = ContainerItem)
TArray<TSubclassOf<class AItem>> ItemsInContainer;
so here i can manually add items to a container or, if it doens’t have any, random populate the “ItemsInContainer” array from the ItemDB like this:
if (ItemsInContainer.Num() == 0){
int32 itemsQuantity = FMath::RandRange(0, 3);
if (itemsQuantity > 0){
ASurvivalGameMode* ASGM = Cast<ASurvivalGameMode>(GetWorld()->GetAuthGameMode());
for (int32 i = 0; i < itemsQuantity; i++){
int32 randomIndex = FMath::RandRange(0, (ASGM->InventoryManager->GetItemDataBaseSize() - 1));
ItemsIndex.Add(randomIndex);
TSubclassOf<AItem> item = ASGM->InventoryManager->ItemDB->GetItemById(randomIndex);
if (ASGM->InventoryManager->ItemDB->GetItemById(randomIndex) != NULL){
ItemsInContainer.Add(item);
}
}
}
}
Now when i interact with this container actor, it should return instances of items wich are in “ItemsInContainer” in order to show the properties like “item descripcion” “item name” “item value” etc to a UMG widget.
SO here is the problem, if i spawn every item in every lootcontainer, i will end up woth a lot of spawned items all around the scene (wich i could hide or set not visible), but they still be there, but i cant find other way to do this.
Hope you / someone understand my problem
And im sorry for the wall of text