playMaker

Author Topic: Destroying three prefabs and Array Index errors.  (Read 4352 times)

coffeeANDsoda

  • Hero Member
  • *****
  • Posts: 618
Destroying three prefabs and Array Index errors.
« on: March 28, 2016, 04:37:11 AM »
Hello, I've been having a problem with a array index issue. So I have a manager FSM that adds game objects after they are created, and another object with a fsm that is suppose to destroy three prefabs created when they are on a proxy list.

So when this trigger gets a tag from the prefab objects, it stores it in a local integer variable, when the player pushes three, it is suppose to be stored in a global variable then it transitions into another state that identifies with a int compare action. The problem I'm having is after it only destroys one prefab(which I do have that stored in a global ), I get a error after it is in the same state as a array list remove range action.

Code: [Select]
Index and count do not denote a valid range of elements.
Parameter name: index
UnityEngine.Debug:LogError(Object)
HutongGames.PlayMaker.Actions.ArrayListRemoveRange:doArrayListRemoveRange() (at Assets/PlayMaker ArrayMaker/Actions/ArrayList/ArrayListRemoveRange.cs:70)
HutongGames.PlayMaker.Actions.ArrayListRemoveRange:OnEnter() (at Assets/PlayMaker ArrayMaker/Actions/ArrayList/ArrayListRemoveRange.cs:55)
HutongGames.PlayMaker.FsmState:ActivateActions(Int32) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:200)
HutongGames.PlayMaker.FsmState:OnEnter() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:168)
HutongGames.PlayMaker.Fsm:EnterState(FsmState) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2155)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2113)
HutongGames.PlayMaker.Fsm:UpdateStateChanges() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2041)
HutongGames.PlayMaker.Fsm:UpdateState(FsmState) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2171)
HutongGames.PlayMaker.Fsm:Update() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1425)
PlayMakerFSM:Update() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:431)


Again my goal is to destroy three objects that collide with the destroy cube trigger and clear them from the array list on the manager.

coffeeANDsoda

  • Hero Member
  • *****
  • Posts: 618
Re: Destroying three prefabs and Array Index errors.
« Reply #1 on: March 28, 2016, 03:16:21 PM »
Forgot, this is what I have so far for both fsms. And the prefab blocks do not have fsms.

https://db.tt/Jqqowj2U

https://db.tt/I1E5J6Re

https://db.tt/koYT3Ijp

https://db.tt/RQx0PkMl

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Destroying three prefabs and Array Index errors.
« Reply #2 on: March 29, 2016, 01:56:21 AM »
Hi,

 I see, maybe I should remove the LogError.

 The issue is that you try to remove a range that goes indeed out of range... so you first need to make sure your index and count values are within the range of the array.

 can you do the following:

-- comment or delete line 70 of ArrayListRemoveRange
-- implement the failureEvent in your logic to catch when it fails, and use this to understand how to set up the index and count.

for example, if you want to remove the first 2 entry, index = 0 count = 2

Bye,

 Jean

coffeeANDsoda

  • Hero Member
  • *****
  • Posts: 618
Re: Destroying three prefabs and Array Index errors.
« Reply #3 on: March 30, 2016, 12:58:42 AM »
When I use a failure result on remove range and set the count down to 2, I still get the same error.

What would "Debug.LogError(e.Message);" do in terms of having it run? Because when I modified the script, I get a message in regards to assets.

Code: [Select]
Assets/PlayMaker ArrayMaker/Actions/ArrayList/ArrayListRemoveRange.cs(69,49): warning CS0168: The variable `e' is declared but never used
When I have the current setup being what it is right now, it destroys only one cube, not three, and after awhile, runtime pauses and the error appears.
« Last Edit: March 30, 2016, 01:02:13 AM by coffeeANDsoda »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Destroying three prefabs and Array Index errors.
« Reply #4 on: March 30, 2016, 01:44:52 AM »
Hi,

 Simply remove the logError() all together.

as for the warning about the 'e' variable never used, it's fine you can ignore that. and if that's really annoying you, simply put a

Quote
#pragma warning disable 0168
in your script and the warning will be silenced.

https://msdn.microsoft.com/en-us/library/441722ys.aspx


 However, you do realize that you actually need to fix this issue instead of trying to silence it :) removing a range needs to be precise, if you give an index and count that leads to trying to remove items out of range, this is a bug in your logic problem, not a really a "feature" :)

 If however, you think your index and count is right, then let's look at the problem and isolate the issue, ok?

Bye,

 Jean

coffeeANDsoda

  • Hero Member
  • *****
  • Posts: 618
Re: Destroying three prefabs and Array Index errors.
« Reply #5 on: March 30, 2016, 01:58:31 AM »

However, you do realize that you actually need to fix this issue instead of trying to silence it

The issue being that three prefabs created are destroyed when they collide with the trigger and are removed from the array list proxy.

As oppose to only a couple prefabs being removed&destroyed while a few others stay around.
« Last Edit: March 30, 2016, 02:07:01 AM by coffeeANDsoda »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Destroying three prefabs and Array Index errors.
« Reply #6 on: March 30, 2016, 04:34:22 AM »
Hi,

 How do you remove the deleted prefabs from the arrayList proxy? normally if you delete a GamObject that is listed in an array, you get a null reference, but the item stays as indexed. So somewhere I think you are indeed deleting the array entry, am I correct?

 Can you explain what you are trying to achieve with this delete range? If you want to delete three prefabs, but potentially the list as only 2 or less items, always get the "count" of that list, and make sure your index + count properties in deleteRange doesn't exceed the count.


Bye,

 Jean

coffeeANDsoda

  • Hero Member
  • *****
  • Posts: 618
Re: Destroying three prefabs and Array Index errors.
« Reply #7 on: March 30, 2016, 03:31:12 PM »
How do you remove the deleted prefabs from the arrayList proxy? normally if you delete a GamObject that is listed in an array, you get a null reference, but the item stays as indexed. So somewhere I think you are indeed deleting the array entry, am I correct?

In runtime, it would delete a couple of items from the array list, but it wouldn't destroy all three prefabs along with the items in the list, located in the manager. Sometimes it would destroy one prefab, and other times one or two, then at some point the error would appear to pause it. That's not what it's suppose to do.

Can you explain what you are trying to achieve with this delete range?

Why use a delete array range type of action? To keep things basic and stripped down, the point of the trigger set up is to have 1 invisible cube trigger that detects each prefab objects collision&tag, and if two more are pushed into that trigger cube by rigidbodies colliding with the rigidbody attached to the player, the trigger detects a prefab containing a local int variable in order to compare it via a int compare action in another state.

So since this isn't some sort of advanced gameplay mechanic system like a match 3 or tetris clone where you'd have to figure out a way for each prefab obj being made with individual triggers attached to detect which variable or different tag that each prefab collides with, it should work like the following...



If three prefab objs(blocks for example) collide with a trigger cube,  then not only they are removed from a array list proxy located on another separate object manager, but they are destroyed because the cube trigger deals with detecting each cube as some sort of local int variable in order to be compared to the trigger detecting three prefab block objs.

I can't think of another way to set up an fsm to detect and destroy a certain amount of blocks unless comparing ints comes in to equation. I did try the int add action, but would crash unity after 3 ints were added when the trigger cube transitioned into a int compare state. And that was on a different scene with a different obj manager FSM. Therefore, I used one int var. And a couple of global GameObject variables, one for storing blocks, and the other for resetting the array list.

So for the recap...

1 trigger detects three prefabs, each one them count as 1 int on 1 local int var that would destroy all three blocks because 1 prefab = 1 block. 

Last I checked, there were a couple of global variables in this scene. But only because I want to try to do this without having each block have a template FSM with global events in order to communicate with the cube trigger and empty object with a array list proxy manager.

Does that sound clearer to you Jean? Or does it still sound too convoluted? I thought that hey! In order to try something more simplified compared to making a full on match3 type of game, I'd try this for practice.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Destroying three prefabs and Array Index errors.
« Reply #8 on: April 06, 2016, 01:49:07 AM »
Hi,

 yeah :)

 The thing is, the action works well, you need to properly get the number of items in the array you want to deleteRange to and compute the index and count properly.

what is the index property value and count value when you get errors? have you compare them two values with the total number of items in the array, do they match, that is index+ count is not greater then the number of items in the array?

Bye,

 Jean