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"

Why do these lines keep crashing my engine?

I can't figure out why, but the following lines keep crashing my engine

Header file:

 private:
 
 //array which holds all players
         UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Zombies", meta = (AllowPrivateAccess = "true"))
             TArray<AActor*> Players;
     
         //array which holds the locations of the players
         UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Zombies", meta = (AllowPrivateAccess = "true"))
             TArray<FVector> PlayerLocations;
 
     //Updates the location of the player to AZombieManager to be able to calculate zombiespawns
     void UpdatePlayerLocations();


cpp file:

 void AZombieManager::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
     TimeSinceLastCalculation += DeltaTime;
     if (TimeSinceLastCalculation >= TimeBeforeNextCalculation)
     {
         UpdatePlayerLocations();
     }
 }
 
 void AZombieManager::UpdatePlayerLocations()
 {
     for (int i = 0; i < Players.Num(); i++)
     {
         if (IsValid(Players[i]))
         {
             FVector TempVector = Players[i]->GetActorLocation();
             PlayerLocations[i] = TempVector;
             UE_LOG(LogTemp, Warning, TEXT("Succesfully updated player location"));
         }
     }
     TimeSinceLastCalculation = 0; // is initializeed in the header file didn't list it in the lines of the header file that has to do with this problem, but is is there as a float
 }

It says that something is wrong in the AZombieManager::UpdatePlayerLocations() but what?

Thanks in advance

-Erik

Product Version: UE 4.12
Tags:
more ▼

asked Aug 07 '16 at 09:48 AM in C++ Programming

avatar image

erik321123
408 17 15 31

avatar image NoobsDeSroobs Aug 07 '16 at 11:13 AM

Please post the error log. We can help more then.

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

1 answer: sort voted first

Is the PlayerLocations array always the same size as the Players array? Coz that would be one reason for the crash, accessing an index from PlayerLocations that exceeds its bounds. Ensure that when a Player is added to the array, that a vector is also added to the PlayerLocations array. And vice versa, if a player is removed, PlayerLocations is updated.

more ▼

answered Aug 07 '16 at 10:44 AM

avatar image

GalaxyMan2015
290 3 4 24

(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