- Home /
Custom Editor + Array = A Long Nightmare !
Ok i know that question has been asked many times but im searching the internet and Unity answers/forums for hours and couldn't find a single solution.(Or i am frustrated and couldn't see what was in front of my eyes,i'm not sure:) )
I'm trying to create an Editor script which will read a sheet and assign it into and array inside the gameObject which is the script is attached.Everything is perfect until here.
But im having trouble assigning that array to the actual script.
I have tried following :
_script = (TextureAtlasReader)target;
//FYI : method below returns a Vector2[][]
_script.frames = CacheAnimation();
EditorUtility.SetDirty(target);
serializedObject.ApplyModifiedProperties();
and this (i was very hopeless and gave it a try :D)
Vector2[][] tempArray = CacheAnimation();
for (int i = 0; i < frames.arraySize; i++)
{
for (int j = 0; j < frames.GetArrayElementAtIndex(i).arraySize; j++)
{
frames.GetArrayElementAtIndex(i).vector2Value = tempArray[i][j];
}
}
Any help would be great.
Summary
class X has a Vector2[][] array. XEditor custom editor have to modify/create this array.
Just to make sure, is the .frames member [Serializable]?
Have you new'd .frames to the correct size and then copied the values into that? I notice that your second example does not show the declaration of .frames, but uses .frames's size to do the copying. $$anonymous$$aybe it's not initialized to what you need?
Have you new'd .frames to the correct size and then copied the values into that?
If you mean if i initialized the array ? If yes the following code returns a Vector2[][] array.So yes it is initialized until i press play button.(Im sure the returning array is not null or empty)
_script.frames = CacheAnimation();
I notice that your second example does not show the declaration of .frames, but uses .frames's size to do the copying. $$anonymous$$aybe it's not initialized to what you need?
Well i rewrote the code to show you guys what i tried so far.So that part is not the actually code so i forgot to include definition part :)
Answer by Nidre · Apr 07, 2013 at 09:48 AM
I found the solution for all those who is searching for similiar issues.
My issue was i was setting the target array when a GUi layout button was pressed.So i think when pressed play it was making another pass before playing and that was resetting the array to its default state.So what i did is moved my array code out of button function.