Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: ... on May 22, 2019, 09:34:58 AM
-
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?
-
Hi,
Can you show the fsm/state/actions
-
Sure
(https://i.postimg.cc/Xv8sJCrf/screenshot-289.png)
That's it, it's completely same everywhere. Here's the array.
(https://i.postimg.cc/tgxVvQjY/screenshot-290.png)
-
Hi.
I mean the flow of the fsm/states.
And also how are you removing, as you mentioned that you are removing them.
-
I don't think flow is of much importance here, it's in the start state.
(https://i.postimg.cc/ZK1sVq1v/screenshot-291.png)
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.
-
Strange thing happened, now i'm getting the same warning instead of error.
-
Hi.
How many enemies are going on and off screen at the same time?
What purpose does the int have?
-
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.
-
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)
-
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.
-
Hi.
Try having a next frame in between.
-
Ok, i'll try it out.
-
Hi,
Did this got sorted out?
Bye,
Jean
-
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.