- Home /
Other
[Photos added]Changing size of list in hierarchy not working.
Above picture: I want to add an element by changing the size to 1 but it doesn't change to one it stays as 0... T.T
PS: I've already put up a lot of questions on this in the past... Nobody knows what the answer....
I have a list like: public List somelist = new List();
and whenever I try to increase the element size (the number of things in the list), it always changes back to zero. Is there anyway to change element size in the script? Help?
I'm not finished but, alright, here's the whole script: using UnityEngine; using System.Collections; using System.Collections.Generic;
public class map: MonoBehaviour
{
public static map instance;
public List<mapsettings> maplist = new List<mapsettings>();
private mapsettings loadmap = null;
void Awake()
{
instance = this;
loadmap = maplist[0];
}
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
void OnGUI ()
{
if(guiscript.startserver == true)
{
GUILayout.BeginArea(new Rect(0,0,500,550))
foreach(mapsettings map in maplist)
GUILayout.Button(map.mapname);
GUILayout.EndArea();
}
}
}
[System.Serializable]
public class mapsettings
{
public string mapname;
public string maploadname;
}
Found similar post: http://answers.unity3d.com/questions/547631/cant-add-animation-element.html
would you be able to include the whole script? its possible you have something on the update function that may be resetting it back to 0.
please post your update function and, as Therain13 mentioned, the whole script pelase
There's no place in the script where you change the size of the List<>
. Please post the parts of the script relevant to the question, nothing more is necessary, but anything less will make it unanswerable.
I have some errors: ArgumentOutOfRangeException: Argument is out of range. Parameter name: index System.Collections.Generic.List`1[mapsettings].get_Item (Int32 index) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633) menumanager..ctor ()
and
Assets/Scripts/map.cs(5,29): warning CS0414: The private field `map.loadmap' is assigned but its value is never used
Line 10, you're getting the first element of an empty list. The List<>
has a length of 0, so how can you get the first element?
Answer by Benproductions1 · Dec 25, 2013 at 11:16 AM
Hello,
The type List<>
is not seizable and is not accessible from the inspector. Therefore it is neither saved nor loaded with a prefab or a scene and will not persist. If you want a collection that is seizable and shows up in the inspector, I suggest you use built-in arrays instead, however they do come with the downside that they are fixed size.
The fact that the List<> mapList
shows in the hierarchy is either due to a custom editor or a very obscure bug. In either case it's incorrect and shouldn't be there.
Hope this helps,
Benproductions1
Thanks for the answer. One more question: Doesn't the list store strings? If so, I could use it for string names for scenes such as Application.LoadLevel(mapname); right? In a tutorial I was following: http://www.youtube.com/watch?v=BU5zRpy2StE ..... At 8:45, he changes the size of the list. How come he can do it and I can't???
That's really not supposed to work. He might have written some extensions to the List<>
class to make it serializable.
Update: I tried array and I still have the same problem!!! I guess it's an error after all. I tried public string[] maplist; and did the increasing size of elements and it still doesn't work... Oh well.
Can you please try to change the size of an array in the inspector and see if it works? I hope I'm not the only one with this bug/glitch...
I've been doing it since I first started using Unity and nothing has changed with any updates. Try doing it in a new project. If that doesn't work reinstall Unity. If that doesn't work then install an older version of Unity. If that doesn't work reinstall your OS and if that doesn't work... well... we're all screwed then
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Inherit size of particles from parent 0 Answers
Texture Doubled in size in RAM Profiler 3 Answers
JSON deserialization 0 Answers
Sorting Game Object Name In Numerical and Alphabetical Order via List 2 Answers