Blueprint Array Remove Index/Item and Event Tick interaction bug

Hi,

Using 4.10.2, I’ve discovered that the blueprint nodes “Remove Item” and “Remove Index” for arrays of actors do not appear to function correctly when the array itself is iterated over in a event tick.

If you have an array of actors that are accessed and processed during an event tick, and then remove and destroy one actor in the array, you will receive errors in the PIE log after exiting, telling you the actor is still in the array and pending kill. If the array is not iterated over in the event tick, things seem to work normally.

I created a sample project with this bug: when the 2D example map is open and played, the player character creates a bunch of ledge actors which get added to an array that is iterated over in Event Tick. Pressing Q removes and destroys one actor, then closing the PIE will bring the errors in the logs to the fore. If the iteration in the Event Tick is removed, and instead pressing R is used to remove an actor, there is no problem.

I understand that this might be my error, and that in fact the Remove Item and Remove Index nodes do not remove the item or index immediately - however, I’ve not seen any documentation about this. Either way, bug or not, does anyone have any suggestions as to how to remove the actor from the array while still iterating? Or would the simplest solution be to halt the the processing in event tick for some amount of time (0.1 secs?) and resume once the actor has been removed and destroyed?

All help appreciated, and if this is a bug and more detail is needed, please ask!

Thanks.

Hi MkII,

After testing this, all you need to add is an IsValid check before triggering the Custom Event in the platform blueprint. Since one of the platforms is destroyed and no longer valid, it causes errors if you attempt to activate the event.

Let me know if that works for you or not.

Cheers,

TJ

That does indeed fix the problem, thanks! I’m still unsure why the array still contains the actor in this case, and I’ll need to do some checking to see that the actor is indeed removed at some point - if you happen to know what exactly is going on here, please do let me know! I realise the actor is still around while it’s being destroyed, but I expected the Remove Index node to immediately remove the actor from the array.

To completely remove it from the array you may need to resize the array after the platform is removed/destroyed.

In the end I decided not to let anything remove and destroy the actor in the array, and instead let game objects add to a queue of actors to be destroyed. Then, at the end of the processing in event tick I can destroy and remove them safely in the actor that owns the array. This seems to work; next time I might try resizing as you suggest. Cheers!