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!

Where is your changeTargetForAllOrbs() function being called from? Update, Awake, elsewhere?

2 Answers

2

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//);

List isn’t broken. If the .Count says 0, that means there are no items in the list.