Trying to remove hism instances with a reverse for each loop.
It only removes 3 then stops, a print string tells me the array is much bigger.
Why is it only looping through 3 times then stopping?
Any help appreciated.
Trying to remove hism instances with a reverse for each loop.
It only removes 3 then stops, a print string tells me the array is much bigger.
Why is it only looping through 3 times then stopping?
Any help appreciated.
I don’t know exactly what’s happening here, you need to break your debugging down into stages.
What I can tell you, is you don’t need a reverse for loop. That’s for when you’re removing items from the array, which you aren’t doing here.
I have a print string printing the elements before the removal and I can confirm the array has 30+ instances in it with the correct hits… But the loop only removes like 3 then stops?
… I am trying to remove instances. I just clear the array at the end.
I have a print string printing the elements before the removal and I can confirm the array has 30+ instances in it with the correct hits… But the loop only removes like 3 then stops?
If you remove an index, some other indexes will be redistributed - jumbled. It does not matter here that you’re doing it in reverse - the indexing within the HISM does not work like a regular array where elements are neatly ordered; they cannot be discarded / (re)moved around while others keep their spot.
You cannot have a situation where there is no index 5 in HISM with 10 instances. The moment you remove 5, number 8 may become 6.
If you want to remove a bunch of indexes, add them to an array and [bulk-remove][1] in one go rather than one-by-one. There are linked examples of this in the other thread where we talked about casting.
Or even better, have a look at how [Sets][2] work - they offer very efficient operations that work really well with HISM indexes. As in:
This way you do not even need to use AddUnique. A Set will ensure values are unique. And there’s no more iteration, it all happens in one go.
But you have both. You’ve build the Unique Array - Remove Instances instead of the 2nd reverse loop.
Hmm remove instances node that takes
the array still only removes 1
instance, but not the others.
Remove Instances
will remove all valid instances from the target HISM that were listed in the provided array.
If you were to do it on-by-on in a loop, every time you remove an index from a HISM, their order will get updated. Then, were you to attempt removal of another element, the indexing data you originally had is now stale, the array no longer reflects the order of the HISM indexes. And you’ll be removing something at random, providing it even exists…
Also, be careful with Instance Count, you’re doing 1 index too many in the For Loop. Ensure the last index is Instance Count-1.
But you can’t bulk remove because you need both the component ref and the specific index, no?
Hmm remove instances node that takes the array still only removes 1 instance, but not the others.
Hmm Okay, I ended up figuring it out.
Everything was working as intended but when the instances got removed they didn’t appear to visually update. I restarted my project and it works now? Hurray?
Thanks for the help anyways I ended up going with just the remove instances with the array plugged in. Until next time!