How can I set properties on multiple clones in a generic list after instantiation.

I don’t understand why this does not work:

Vector3 pos = new Vector3(x,0,y);    				
TerrainTiles.Add(Instantiate(Resources.Load("Prefabs/TerrainTile"), pos, Quaternion.identity) as TerrainTile);
Debug.Log("List items: " + TerrainTiles.Count.ToString());
TerrainTiles[TerrainTiles.Count - 1].xPosition = x;

Running the debug log shows that the list items are being created but when I try to reference any of them as in the last line of code above I am getting a NullReferenceException.

Have you tried using a version of Resources.Load that uses an explicit Type?

TerrainTiles.Add(Instantiate(Resources.Load("Prefabs/TerrainTile", typeof(TerrainTile)), pos, Quaternion.identity) as TerrainTile);


TerrainTiles.Add(Instantiate(Resources.Load<TerrainTile>("Prefabs/TerrainTile"), pos, Quaternion.identity) as TerrainTile);