- Home /
 
               Question by 
               Woj_Gabel_FertileSky · Feb 12, 2012 at 02:51 PM · 
                arraylistcountgeneric list0  
              
 
              Generic List.Count always gives 0
Hi All! Is generic List somehow broken in unity? Im using unity free. Problem is orblist.Count is always giving me 0.
 import System.Collections.Generic;
 
     var orblist = new List.<GameObject>(); 
     
     function changeTargetForAllOrbs (newTarget : GameObject)
     {
     print(orblist.Count);
     for(i = 0; i<orblist.Count; i++)
       {
         print("please work!");
       }
     }
This is weird, because when adding :
 print(orblist.Count);
in Update it will work and give me correct number if instances in List. Help!
               Comment
              
 
               
              Where is your changeTargetForAllOrbs() function being called from? Update, Awake, elsewhere?
Answer by Eric5h5 · Feb 12, 2012 at 07:52 PM
List isn't broken. If the .Count says 0, that means there are no items in the list.
Answer by Kumar_saki · Oct 11, 2017 at 04:42 AM
You never actually added anything to the list in this code. If you want to add any thing to your list, use orbitlist.Add(//the gameobject u want to add//);
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                