No announcement yet.

if I remove index from array

  • Filter
  • Time
  • Show
Clear All
new posts

    if I remove index from array

    let#s say I have 4 elements in 1 array variable.

    I remove index 0.

    Do the other elements slide 1 slot up? Element (slot 1) moves to slot 0?
    Last edited by Plautus123; 07-04-2017, 10:39 PM.

    No, arrays don't adjust like that, types that do are called are queues and deques. See this


      We are not in C++. Blueprint Arrays are implemented as LinkedLists.
      Removing Index 0 causes all elements to push up.
      This can be a problem when altering items in the array and deleting items at the same time.
      Use a reverse for loop if you want to iterate over and delete items.


        so I was right


          Blueprint arrays which are basically Epic's TArray, will slide Down to fill the empty index if an index was removed, I think your slot up terminology confused things a bit leading to the answer of queues and dequeues. Insert will "push up" so any items in the array after the insert will be one index higher.

          index 0 = bob, index 1 = harry, index 2 = jerry. Remove Index 0.
          index 0 = harry, index 1 = jerry.

          Insert index 1 "charlie."
          index 0 = harry, index 1 = charlie, index 2 = jerry.

          Set Array Elem will just alter that index without changing order. So in continuing:
          Set Array Elem index 2 item to Joey.
          index 0 = harry, index 1 = charlie, index 2 = Joey.

          Set Array Elem also includes an automatic resize option, which if checked will automatically resize the array so it can contain that index. Keep in mind if it was done multiple spaces after the last index, the indexes inbetween will be filled with the default value of that type.

          So yes you are right.
          Indie Dev - Whiskey Cat Softworks
          Currently developing a colony survival game!


            I know this post is old, but if you want to remove an index from an array and have the array basically stay the same then don't "remove" the index. Instead replace the index with something else. If this is being used for something like an inventory you can just have an "empty" array object and just fill the entire array with this. When you add to the array you just replace the empty element with an actual item. Then when you want to remove something you just replace the item with the "empty" object.