Is it maybe because im missing something in regards to initializing the Inventory Array because I am doing the .add function within an actor component? The Item is getting the meshes from the datatable fine but when I run the additem function the Inventory.Add() causes the debug to say : Access violation reading location
Item -
// Called when the game starts or when spawned
void AMItem::BeginPlay()
{
Super::BeginPlay();
SetInfo();
}
UWorld* AMItem::GetItemWorld()
{
return this->GetWorld();
}
AMGameGameModeBase* AMItem::GetMyGameMode()
{
return Cast<AMGameGameModeBase>(GetItemWorld()->GetAuthGameMode());
}
FName AMItem::GetName()
{
return ID;
}
void AMItem::SetInfo()
{
AMGameGameModeBase* GameMode = GetMyGameMode();
bool Found = false;
FItem ItemFound = GameMode->FindItem(ID, Found);
if (Found)
{
SkeletalMeshComponent->SetSkeletalMesh(ItemFound.Mesh.SkeletalMesh);
StaticMeshComponent->SetStaticMesh(ItemFound.Mesh.StaticMesh);
}
}
void AMItem::Interact_Implementation(AActor* Caller)
{
InventoryComponent->AddItem(GetName(), this);
}
Inventory Component
add item -
void UMInventoryComponent::AddItem(FName ItemID, AMItem* Item)
{
AMGameGameModeBase* GameMode = Item->GetMyGameMode();
bool bItemFound = false;
FItem ItemFound = GameMode->FindItem(Item->ID, bItemFound);
if (bItemFound)
{
FItem NewItem;
NewItem.ID = Item->ID;
NewItem.Quantity = ItemFound.Quantity;
NewItem.MainParameters.Abbreviation = ItemFound.MainParameters.Abbreviation;
NewItem.MainParameters.EquipType = ItemFound.MainParameters.EquipType;
NewItem.MainParameters.InspectImage = ItemFound.MainParameters.InspectImage;
NewItem.MainParameters.InventoryImage = ItemFound.MainParameters.InventoryImage;
NewItem.MainParameters.IsUsable = ItemFound.MainParameters.IsUsable;
NewItem.MainParameters.Name = ItemFound.MainParameters.Name;
NewItem.MainParameters.SizeX = ItemFound.MainParameters.SizeX;
NewItem.MainParameters.SizeY = ItemFound.MainParameters.SizeY;
NewItem.MainParameters.StackSize = ItemFound.MainParameters.StackSize;
NewItem.MainParameters.UseType = ItemFound.MainParameters.UseType;
NewItem.Mesh.SkeletalMesh = ItemFound.Mesh.SkeletalMesh;
NewItem.Mesh.StaticMesh = ItemFound.Mesh.StaticMesh;
Inventory.Add(NewItem);
//Inventory.Add(NewItem);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor(255, 255, 255), "SetInfo");
}
}