While working on a project, I encountered a problem when removing actors from an array.
After encountering this weird problem, i started a clean project in UE4 to reproduce the issue, which I was able to.
What I’m trying to achieve:
When pressing a button, an actor is spawned and added to an array. When pressing Z I’m removing this item from the array and destroying the actor.
Using an integer variable, the “Destroy Actor” function doesn’t destroy anything, but the items get correctly removed from the array.
In more detail:
I attempted using “Last Index”, but it removed every item in order, except the last one that was spawned. I then tried using an Integer that would get the index number from the array, this did not work at all, it removed the items from the array, but the items did not get destroyed. I then tried to make this integer get its value directly from the “last index” on the array. To my surprise this didn’t work either, however connecting the last index directly, did.
This seems really strange to me, as both the Integer variable and the “Last Index” are outputting an integer value.
I’m not sure if I’m doing something wrong, or have encountered a bug.
Could you help me figure out why it does this? And if you know how to get the last actor spawned removed as well, that would be great!
Short video showcasing the issue: [UE4 - Removing from array issue - YouTube]
I’m gonna leave the project files here, in case you need that: