Am I using Arrays right? Im getting errors and weird results...

I have an array of Actors
image

It’s defined as follows:

I fill the array by calling this multiple times

But when I want to Destroy the actors and clear the array back down to a zero length array I call this: (EDIT: I properly linked the Array Element to the Remove - but still having stuck items in array)

And I’m getting weird results :

  1. sometimes it doesn’t Remove or Destroy Actor on BP_Coins I have put into the array
  2. sometimes I get errors on accessing the actor (BP_Coins) when doing a For Each loop thru the array…

Maybe there is a way to just reset coinsUsedArray to be empty and zero length rather than iterate through it and doing “Remove” on each item?

I guess the issue here that you are taking not exactly an actor from the array, but rather a reference to the object inside of array, so when you remove the object from array this reference gets messed up and thats why destroy actor fails.
For your case I would suggest you just to destroy all the actors in the for each loop and then call Clear method on Array (Clear | Unreal Engine 5.4 Documentation | Epic Developer Community)
Everything will be destroyed correctly and array will be empty)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.