Instantiate to temp var or directly adding to list?

When instantiating an object with properties other than the original prefab, is it better to do this:

Declare a temp var and change its properties, then add to list

var o:GameObject = Instantiate(fred,Vector3.zero,Quaternion.identity);
o.renderer.material.color = RandColor();
list.Add(o);

or this:

Add to list directly, then reference last added list element to change its properties.

list.Add(Instantiate(fred,Vector3.zero,Quaternion.identity));
list[listCount].renderer.material.color = RandColor();

1 Answer

1

I’ll go for the first one, as you spare yourself a list access. Not much of a difference though.