playMaker

Author Topic: Arraylist not being cleared completely  (Read 1135 times)

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Arraylist not being cleared completely
« on: April 19, 2020, 04:52:08 AM »
Hi guys,

i'm having an issue with an arraylist, could be i'm not doing something good, could be a bug.

I have the arraylist prefilled with 17 game objects which represent some perks that can be picked up when you kill the boss. So, when you do kill it, a dedicated spawner spawns the perks and for each spawned perk it removes it from the arraylist so it isn't spawned again.

That works ok, 4 perks are spawned and 4 are removed from the arraylist, so 13 remain.

When you pick up any of the perks, a Perk Controller removes the remaining game objects from the arraylist so it can be repopulated. However, instead of removing all 13 game objects, it removes only 8 and finishes. I believe the setup is correct, there's nothing to it really, i tried forcing the iteration too, but to no avail.





I also tried with clear arraylist action instead of iterating through the array, i also get the same result, 5 items are left in the array.

I'm using Unity 2018.3.8., latest PM beta.

Btw, i also get this when i use the Max Rows slider during play mode:

InvalidOperationException: This cannot be used during play mode. EditorSceneManager.MarkSceneDirty() at None
« Last Edit: April 19, 2020, 04:54:09 AM by krmko »
Available for Playmaker work

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Arraylist not being cleared completely
« Reply #1 on: April 19, 2020, 05:45:01 AM »
I mean i can empty it by removing items at index 0 until it fails, that works, but i really want to get into why doesn't this work the proper way.
Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Arraylist not being cleared completely
« Reply #2 on: April 19, 2020, 07:58:57 AM »
Hi.
You Are removing from the list that you are referring to.
which changes the list.
so in theory you would need to reset the array get next as it will still think that it is the same array length. (and therefore you might get out of range issues as well.)

and also 1st it will remove at index 0. so then it moves index 1 to index 0.
and array get next will get index 1 as next (so old index 1 is skipped)

But array list clear should work. try setting some break points if it gets populated from somewhere else.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Arraylist not being cleared completely [SOLVED]
« Reply #3 on: April 19, 2020, 01:43:49 PM »
No, it's not populated from elsewhere, i checked. So if i have 13 objects remaining it basically kind of skips every second one so i'm down to the result that i'm getting.

Removing index 0 until it fails is actually the best way to handle this imo but i'm not sure why i'm getting the same result with clear array, but i'll get down to it. Anyway, this concludes it for now, thanks a lot.
Available for Playmaker work