The first blueprint is some breakable glass, when the glass is broken it will add itself to an array in the second blueprint.
The second blueprint contains the array and an integer for counting how many times an actor is added to the array. When it becomes greater than 4, It will decrease the counter by one and destroy the first actor in the array and continue to the next one. (This is for optimization purposes to ensure there is not too much broken glass being rendered)
What I can’t figure out is how to destroy the 1st actor in the array, remove it from the array and then cycle to the next one.
In short: Break Glass > Add to array in another BP > Add 1 to counter > When counter hits 5 Destroy 1st actor in array > Remove Actor from array > Add 5th actor into 1st array slot > Get ready to destroy and remove 2nd array slot > Cycle through.
I get an error when trying to destroy the first item in the array and it won’t seem to cast to the actor to call an event for destroying itself either.
It’s been a minute, but I could have swore Arrays auto shifted indexes in UE.
For example if you remove an index (say 2) the array would shift all the elements down the line, thus refilling index 2.
Index 3 → 2
Index 4 → 3
Index 5 → 4
etc.
If that’s not the case a Shift function is pretty easy to set up.
@Z3R0K0
You do not need to cast the element in the array. Destroying an actor only requires an actor reference. It doesn’t care what the actors class is. Being technical the array should be of type Actor Obj Ref.
That being said, Add an actor reference to the Glass Array when one is broken. Immediately check the Length of that array. If it’s Equal to your control N, then Destroy index[0], remove index[0].
Index[0] will always be the oldest element in the array.
This works, sort of. It seems to be destroying the last actors added to the array instead of the first.
It will keep destroying the most recently added but leaves the first 5 on scene.