- Home /
Odd Behaviour with Lists (Collections.Generic) - Bug?
Okay, this is really odd, and I can't figure it out at all. I'm assuming it's a bug somewhere within Unity. But check this out:
I have two lists:
var ProfileUsername : List.<String>;
var ProfileSubtext : List.<String>;
I then have this function that creates a new profile, it just adds new entires into the list:
public function AddNewProfile(){
print("[PROFILE] Add new profile");
ProfileUsername.Add("New Name");
ProfileSubtext.Add("Subtext tag");
print("Username Count: " + ProfileUsername.Count);
}
Whats weird is that is puts both 'New Name' and 'Subtext tag' into my ProfileUsername, and ProfileSubtext:
How is this happening? My print 'Username Count' also returns a count of 2 entries .
UPDATE
In fact, it adds it to all my List variables within my script.
Answer by koblavi · Jun 02, 2015 at 11:46 PM
I just run the code you have above and it seems to work just fine. Only difference is that I have my start function calling AddNewProfile()
class TryThis extends MonoBehaviour{
var ProfileUsername : List.<String>;
var ProfileSubtext : List.<String>;
function Start () {
AddNewProfile();
}
public function AddNewProfile(){
print("[PROFILE] Add new profile");
ProfileUsername.Add("New Name");
ProfileSubtext.Add("Subtext tag");
print("Username Count: " + ProfileUsername.Count);
}
}
There's a possibility that some other scripts in your project might be doing this.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Items not destroying. 1 Answer
JSON deserialization 0 Answers
Sorting Game Object Name In Numerical and Alphabetical Order via List 2 Answers
List.Contains problem 1 Answer