- Home /
Array of vectors lost in runtime, but not null
I'am trying to set and array of vectors using a custom editor button so it is created out of runtime. The vector is ok and looks good but when I start the program and try to access the vector elements gives an error: "Array index is out of range" If I check if the vector is null it is not and if I check for example the element 0 of the array it still says it is not null. If a try to print the Length it gives me 0 so I am very confuse...also if I check the array in the inspector is say that it have a lot of elements but all in 0...some one can tell me whats going on? how can I keep the vector from the editor to the runtime scene?
I already did this with a normal vector of ints and it works.
thak you.
Have you seen this answer? https://answers.unity.com/questions/1298321/custom-editor-script-resets-values-on-play.html
thank you! I was trying that that but following other similar answer and they didnt work, that one make it. I hava a question. Why only fails with the array of vectors? all the other variables are ok even the arrays of ints, floats and bools. That is weird for me.
I can't be sure (someone please correct me on this if I'm wrong), but my guess is that while all the standard C# data types are serialized, the more complex structs and classes of Unity are not. Also, I think all private fields have to be manually marked for serialization for that to work. Check out this page: https://docs.unity3d.com/$$anonymous$$anual/script-Serialization.html, it looks like it explains a lot of the serialization process in Unity. I'm going to read it myself as well. :)