playMaker

Author Topic: Index was out of range when adding an item to arraylist[SOLVED]  (Read 2981 times)

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Hi guys,

i have an identical FSM in all of my enemy prefabs that adds a number (int) to an arraylist when the enemy enters the screen, and removes an item when the enemy goes out of the screen. It works flawlessly except on one prefab that reports an "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" error.

I don't get it, it's a completely same action (array list add) with completely same parameters on all objects.

Any ideas?
« Last Edit: May 31, 2019, 09:53:38 AM by jeanfabre »
Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Index was out of range when adding an item to arraylist
« Reply #1 on: May 22, 2019, 09:58:37 AM »
Hi,
Can you show the fsm/state/actions

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Index was out of range when adding an item to arraylist
« Reply #2 on: May 22, 2019, 10:06:06 AM »
Sure



That's it, it's completely same everywhere. Here's the array.

Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Index was out of range when adding an item to arraylist
« Reply #3 on: May 23, 2019, 01:30:32 AM »
Hi.
I mean the flow of the fsm/states.

And also how are you removing, as you mentioned that you are removing them.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Index was out of range when adding an item to arraylist
« Reply #4 on: May 23, 2019, 02:14:24 AM »
I don't think flow is of much importance here, it's in the start state.



I replaced the arraylist add action with array list add range and it works now, maybe it should be inspected to check for bugs.

For removing from the array list i use array list remove at end remove the item from index 0, as simple as that, no mistake there.

Edit: nah, there's still errors.
« Last Edit: May 23, 2019, 11:39:20 AM by krmko »
Available for Playmaker work

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Index was out of range when adding an item to arraylist
« Reply #5 on: May 24, 2019, 03:29:47 AM »
Strange thing happened, now i'm getting the same warning instead of error.
Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Index was out of range when adding an item to arraylist
« Reply #6 on: May 24, 2019, 04:22:46 AM »
Hi.
How many enemies are going on and off screen at the same time?

What purpose does the int have?

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Index was out of range when adding an item to arraylist
« Reply #7 on: May 24, 2019, 04:27:47 AM »
It's just there to fill the array so i can get the count. I reckon an int takes the least processing of all data types.

No enemies get in the screen until the array is empty (enemies are either dead or left the screen), so it's quite fail safe in that regard.

There are instances when 10-20 enemies appear at the same time and are to be added to the array, but the problem happens regardless of enemy number.
Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Index was out of range when adding an item to arraylist
« Reply #8 on: May 24, 2019, 06:52:13 AM »
Hi.
Is there some state between the 'Array List Add' and the "Array List Remove" that has a delay? (wait or next frame event)

Also did you try the same with a int and use 'Fsm Int Add' (add -1 for remove)

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Index was out of range when adding an item to arraylist
« Reply #9 on: May 24, 2019, 07:20:28 AM »
No delays.

I haven't tried, but i figured out more elegant solution. I simply added a disabled tag child to the enemy, when it enters the screen, the tag activates, when it exits or the enemy is destroyed, the tag holding object is deactivated (or destroyed) and the spawner is checking the tag count instead of counting the items in the array. When it's zero, it will spawn another wave.

Unfortunately, get tag count uses find objects so it's not quite good performance-wise, but it works.

Nevertheless, i'm really curious why doesn't this work properly since i'll probably need it again sooner or later and i can't seem to find the way to debug it.
Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Index was out of range when adding an item to arraylist
« Reply #10 on: May 24, 2019, 07:34:15 AM »
Hi.
Try having a next frame in between.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Index was out of range when adding an item to arraylist
« Reply #11 on: May 25, 2019, 10:06:23 AM »
Ok, i'll try it out.
Available for Playmaker work

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Index was out of range when adding an item to arraylist
« Reply #12 on: May 30, 2019, 02:46:33 AM »
Hi,

 Did this got sorted out?

 Bye,

 Jean

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Index was out of range when adding an item to arraylist
« Reply #13 on: May 30, 2019, 03:14:30 AM »
I sorted it out by changing the system altogether (by using tag count), since i'm knee deep and i can't afford to switch to array again to try putting in the next frame for test sake. I'll be probably using more array lists in the future so i'll keep this in my sights.
Available for Playmaker work