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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Destroying an array of SplineMeshComponents

I'm trying to destroy all the elements of an array of spline mesh components using a for loop to destroy each mesh but every time it enters the array, the editor crashes and tells me: Array index out of bounds : 16 from array of size 16(The size of the array will be changing at runtime so I can't create a static array). I appreciate any help on what is the proper way of doing this task. Note I have tried setting index to just the array's Num() without the -1. But this does not fix the issue either.

 void ControllerItem::ClearArc()
 {
     if (splineMeshes.Num() > 0)
     {
         for (int32 index = splineMeshes.Num() - 1; index > 0; index--)
         {
             splineMeshes[index]->DestroyComponent();
         }
         splineMeshes.Empty();
         ArcSpline->ClearSplinePoints(true);
     }    
 }
Product Version: UE 4.14
Tags:
more ▼

asked Jan 04 '17 at 02:10 PM in C++ Programming

avatar image

Oldsiren
161 24 25 31

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

1 answer: sort voted first

I found a solution which works really well:

 void ControllerItem::ClearArc()
 {
     //Checks if it is valid at index zero because index zero is always going to exist if the array has any elements
     if (splineMeshes.IsValidIndex(0))
     {
         while(splineMeshes.IsValidIndex(0))
         {
             //Debug message for checking to see if a spline was destroyed(which it is).
             UE_LOG(LogTemp, Warning, TEXT("DestroyComponent Called on object: %s"), *splineMeshes[0]->GetName());
             //This destroys the component but it does not remove it from the array.
             splineMeshes[0]->DestroyComponent();
             splineMeshes.RemoveAt(0);
         }
     }
 
     ArcSpline->ClearSplinePoints(true);
 }

more ▼

answered Jan 04 '17 at 05:26 PM

avatar image

Oldsiren
161 24 25 31

avatar image Load Time Feb 18 '17 at 05:35 AM

You rock!!!!! Thank you for answering your post. This problem was testing my patience.

(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