Hello and thanks for looking at my problem. I am working on a stackable inventory using a struct. In my struct, FInventoryItem I specify a Quantity and MaxStackSize to denote how many to add and the maximum one entry can hold. My Itteration works, I can add quantity, and as I specify, if the quantity reaches the MaxStackSize creates a new entry. My first issue is that even though the code is working, I am recieving an ensure error on the third stack. My second issue is that when the third stack is created, it creates a 4th as well. Here is the code:
if (GameMode)
{
UDataTable* ItemTable = GameMode->GetItemDB();
if (ItemTable)
{
UE_LOG(LogTemp, Warning, TEXT("Item Table Set"));
FInventoryItem* ItemToAdd = ItemTable->FindRow<FInventoryItem>(ID, "");
if (ItemToAdd)
{
UE_LOG(LogTemp, Warning, TEXT("Item to Add"));
if (ItemToAdd->bIsStackable)
{
UE_LOG(LogTemp, Warning, TEXT("bool called"));
if (InventorytoAdd->Inventory.Contains(*ItemToAdd))
{
UE_LOG(LogTemp, Warning, TEXT("Item is in inventory"));
for (auto& Item : InventorytoAdd->Inventory)
{
UE_LOG(LogTemp, Warning, TEXT("for loop called"));
if (Item.Quantity >= Item.MaxStackSize)
{
UE_LOG(LogTemp, Warning, TEXT("quantity too large"));
InventorytoAdd->Inventory.Add(*ItemToAdd);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Quantity: %d"), &Item.Quantity);
Item.Quantity = Item.Quantity + ItemToAdd->Quantity;
}
}
}
else if (!InventorytoAdd->Inventory.Contains(*ItemToAdd))
{
UE_LOG(LogTemp, Warning, TEXT("Item not in Inventory"));
InventorytoAdd->Inventory.Add(*ItemToAdd);
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Bool not working"));
InventorytoAdd->Inventory.Add(*ItemToAdd);
}
}
else return;
}
else return;
}
else return;
and here is the ensure faile:
LogOutputDevice: Error: === Handled ensure: ===
LogOutputDevice: Error: Ensure condition failed: Lhs.CurrentNum == Lhs.InitialNum [File:C:\Program Files\Epic Games\UE_4.19\Engine\Source\Runtime\Core\Public\Containers/Array.h] [Line: 206]
LogOutputDevice: Error: Array has changed during ranged-for iteration!
LogOutputDevice: Error: Stack:
LogOutputDevice: Error: [Callstack] 0x000000005146B6F6 UE4Editor-Core.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x00000000511CAE2A UE4Editor-Core.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x00000000511DECC6 UE4Editor-Core.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x00000000572B7173 UE4Editor-RPGFix-191.dll!UInventory_Component::AddItemtoInventoryByID() [c:\ue4\rpgfix\source\rpgfix\character components\inventory_component.cpp:76]
LogOutputDevice: Error: [Callstack] 0x00000000572BB1DD UE4Editor-RPGFix-191.dll!APickup::Interact() [c:\ue4\rpgfix\source\rpgfix\interactables\pickup.cpp:45]
LogOutputDevice: Error: [Callstack] 0x00000000572B96DF UE4Editor-RPGFix-191.dll!UInventory_Component::execInteract() [c:\ue4\rpgfix\source\rpgfix\character components\inventory_component.h:114]
LogOutputDevice: Error: [Callstack] 0x0000000051A9E094 UE4Editor-CoreUObject.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x0000000051C70771 UE4Editor-CoreUObject.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x0000000051C887A1 UE4Editor-CoreUObject.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x0000000051C8AA72 UE4Editor-CoreUObject.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x0000000051C711DE UE4Editor-CoreUObject.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x0000000051C8AA72 UE4Editor-CoreUObject.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x0000000051A9E094 UE4Editor-CoreUObject.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x0000000051C89D63 UE4Editor-CoreUObject.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004E5FCCFB UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004F80090E UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004F800A7A UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004F83292B UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004F369EF9 UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004F37E755 UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004F3679BB UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004F37D8FC UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004E5D00E4 UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004F6D690B UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004F6DBFE3 UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000005109B713 UE4Editor-Core.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000005109BD3A UE4Editor-Core.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x00000000510BECFE UE4Editor-Core.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004F6FCFC1 UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004F702AE2 UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004EF5BF04 UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004EF6716B UE4Editor-Engine.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000004211D781 UE4Editor-UnrealEd.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x00000000429B9516 UE4Editor-UnrealEd.dll!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000000BAC5EAC UE4Editor.exe!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000000BAD6BD0 UE4Editor.exe!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000000BAD6C4A UE4Editor.exe!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000000BAE4149 UE4Editor.exe!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000000BAE5B57 UE4Editor.exe!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x000000009E403034 KERNEL32.DLL!UnknownFunction ]
LogOutputDevice: Error: [Callstack] 0x00000000A0B83691 ntdll.dll!UnknownFunction ]
I would appreciate any help