Saving and loading cut foliage

I am trying in every way to save the foliage that I cut, I created a structure that contains the reference and the index of the mesh removed in runtime, I saved it in an array, when loading I added 2 print strings that confirm the type of foliage and its index, I apply the “for each” node to the array and consequently “remove instance” also connecting the Index node between them. Unfortunately it does not work. I do not know where to turn, I found only one tutorial but it did not help me.




The index array auto shifts on index removal.

e.g. array 0-100

Remove index 99. Index 100 down shifts to take the slot position of 99.
Remove index 3. The array downshifts. 99 → 98, 98 → 97 etc all the way down to index 0.

Prior to removing you have to sort your remove indexes so the largest index is first. 99, 37, 22, 1

here’s a snippet showing how to sort your index keys.

Essentially get the largest index value and add it to a temp array.


Also should know the loading order is not guaranteed in the instance array. First load your specific instance could be index 1. Next load it could be index 15, 29, 33 etc.

2 Likes

the problem was in the index, I solved it thanks to your help.