Im trieng to make an inv system, but whenever i try to add an item to my TMAP i get an acces violation on
FSetElementId FindId(KeyInitType Key) const
{
if(HashSize)
{
for(FSetElementId ElementId = GetTypedHash(KeyFuncs::GetKeyHash(Key));
ElementId.IsValidId();
ElementId = Elements[ElementId].HashNextId)
{
if(KeyFuncs::Matches(KeyFuncs::GetSetKey(Elements[ElementId].Value),Key))
{
// Return the first match, regardless of whether the set has multiple matches for the key or not.
return ElementId;
}
}
}
return FSetElementId();
}
My Tmap Looks like this:
TMap<AItemBase*, int32> Items;
The function is called like this:
void UInventoryBase::AddItem(AItemBase* item, int32 amount /*= 1*/)
{
if (!Items.Contains(item))
Items.Add(item, amount);
else
Items[item] += amount;
}
wich inturn is called like this:
void AOogleCharacter::PickUpItem()
{
APlayerController* controller = GetWorld()->GetFirstPlayerController();
FVector start = controller->GetFocalLocation();
FVector end = start + controller->GetControlRotation().Vector() * 265;
FHitResult hit(ForceInit);
FCollisionQueryParams RV_TraceParams = FCollisionQueryParams(FName(TEXT("RV_Trace")), true);
RV_TraceParams.bTraceComplex = true;
RV_TraceParams.bTraceAsyncScene = true;
RV_TraceParams.bReturnPhysicalMaterial = false;
FCollisionObjectQueryParams TraceParams = FCollisionObjectQueryParams(ECC_TO_BITFIELD(ECC_WorldDynamic) | ECC_TO_BITFIELD(ECC_WorldStatic));
DrawDebugLine(GetWorld(), start, end, FColor(255, 0, 255), true);
if (GetWorld()->LineTraceSingleByObjectType(hit, start, end, TraceParams, RV_TraceParams))
{
UE_LOG(LogTemp, Warning, TEXT("hit %s"), hit.GetActor());
if (AItemBase* item = dynamic_cast<AItemBase*>(hit.GetActor()))
{
if (IsValid(item))
{
UE_LOG(LogTemp, Warning, TEXT("Adding item %s"), *item->GetName());
inv->AddItem(item);
item->bHidden = true;
item->SetActorEnableCollision(false);
item->SetActorTickEnabled(false);
}
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("You'r not hitting something"));
}
}
Not sure if its needed but ill put my CallStack Locals and Output here too:
http://puu.sh/llhLP/070a08707f.png
http://puu.sh/llhY4/067f20d96f.png
http://puu.sh/lli2v/8f4ef0da00.png
thanks in advance