IndexOutOfRangeException

This is the place to find out how to accomplish something specific with EZ Game Saver.

IndexOutOfRangeException

Postby giza » Thu Jul 26, 2012 4:38 pm

Hi,

I'm getting an IndexOutOfRangeException at line 599 of the GameDataSaver script. This happens each time that I save a dynamically instantiated set of prefabs. The net effect is that the last prefab is not saved properly and appears without any saved attributes in the scene when it is loaded again. The error message is:

IndexOutOfRangeException: Array index is out of range.
GameDataSaver.Save (System.String saveName, Int32 saveNum, System.String objID) (at Assets/Plugins/EZ/Game Saver/GameDataSaver.cs:599)


Do you have any idea what could be causing this? It always affects the last prefab only. When I load the scene only a single copy of this last prefab appears in the saved scene lacking any transform or material attributes whatsoever, i.e. no attributes are saved and it's not instantiated as it should be.

This is so frustrating as this is the last hurdle that I appear to face in getting the simulation finished.

Thanks!

EDIT:

Any help at all would be greatly appreciated. This is the section of code that includes line 599 that is throwing the exception:

// Write the object ID:
PlayerPrefs.SetString(keyBase + "ID", objGUID.ToString("N"));

for (int i = 0; i < members.Length; ++i)
{
// Build the key name:
keyComponentBase = keyBase + i + ".";

// First save the fields:
for (int j = 0; j < members[i].fields.Length; ++j)
{
field = allComponents[members[i].componentIndex].GetType().GetField(members[i].fields[j]);
if (field == null)
continue;

key = keyComponentBase + "f" + j;

//Debug.Log(gameObject.name + " is Writing: " + field.Name + " from: " + allComponents[members[i].componentIndex].GetType().Name);

// Determine if this is an array:
if (field.FieldType.IsArray)
WriteArrayType(key, field.GetValue(allComponents[members[i].componentIndex])); // Calls the appropriate writer for the field type
else
WriteType(key, field.GetValue(allComponents[members[i].componentIndex])); // Calls the appropriate writer for the field type
}
giza
 
Posts: 10
Joined: Sun Apr 29, 2012 1:17 am

Re: IndexOutOfRangeException

Postby Brady » Sun Jul 29, 2012 11:43 pm

Try re-opening the affected prefab in the inspector, making sure that all of its component inspector panes are expanded and visible, and that the inspector is not in debug mode. This should force a refresh of the prefab's components and all associated fields. What it looks like is wrong is the component or member lists are out of sync with the actual components and/or members of the GameObject in question.

If that doesn't work, try doing the same thing as above, only on a scene instance of the prefab. Then once you have viewed all the inspector panes of all the components on the object, click the "Apply" button (to apply any changes to the associated prefab). That should force it to apply the new polled values to the prefab itself.
Brady
 
Posts: 5361
Joined: Tue Jul 06, 2010 11:33 pm

Re: IndexOutOfRangeException

Postby giza » Mon Jul 30, 2012 6:12 pm

Thanks very much Brady! The second option did the trick!
giza
 
Posts: 10
Joined: Sun Apr 29, 2012 1:17 am

Re: IndexOutOfRangeException

Postby valamun » Mon Apr 16, 2018 8:56 am

ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213
ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213
ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213
ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213
ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213
ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213
ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213
ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213
ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213
ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213
ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213ac23213
ac23213
valamun
 
Posts: 23463
Joined: Sat Mar 17, 2018 5:46 pm


Return to EZ Game Saver How to...

Who is online

Users browsing this forum: No registered users and 1 guest

cron