Game Object seems empty after instantiation

Hello, I am creating a new Game Object from a prefab, with Instantiate() method. However, whenever try to access a property of the object I created, it seems to be null. So for example what is the best way to create a instantiate a gameobject and change its name to something else right after. My code is here:

for (int y = 0; y < 5; y++) {
       		 for (int x = 0; x < 5; x++) {
          
				spawnPos = new Vector3(brickPiece.renderer.bounds.size.x*x,brickPiece.renderer.bounds.size.y*y,0);
				GameObject newObj = new GameObject();
					
				newObj	= (Instantiate( brickPiece, spawnPos, Quaternion.identity)) as GameObject;
				newObj.name  = "brick "+(5*y+x); // can not change cuz newObj seems null
					
       	 	}
    	}

The ‘var’ workaround is definitely a clue - we know your expression is returning something, the only question is what. You can use the following to print out the type:

Debug.Log(newObj.GetType());

Just put that immediately above the newObj.name assignment. I copied your code and ran it, and it worked without error on my end. The only thing I can think of is that there is something amiss with brickPiece. Can you try replacing brickPiece in the Instantiate with ‘new GameObject()’ and see if that works?