x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Tmap<> Acces Violation on Add

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:

alt text

alt text

alt text

thanks in advance

Product Version: UE 4.9
Tags:
more ▼

asked Nov 14 '15 at 04:59 PM in C++ Programming

avatar image

RyanM
6 2 4 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

So it seems like i made a mistake in that i used NewObject to created the inv class in the constructor of the player, instead of BeginPlay

more ▼

answered Nov 16 '15 at 09:30 AM

avatar image

RyanM
6 2 4 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question