The question is answered, right answer was accepted
*Solved* Loop instantiating objects causes my Unity Editor to crash
*Solved: Didn't proofread my for loop enough times
Hi everyone, I have been looking for a solution to this, or even an explanation to the cause of my problem for a while now. When I run the following script in Unity the Editor hangs up/crashes on me every single time.
public class LevelManager : MonoBehaviour
{
public LevelManager()
{
}
public void NewLevel()
{
var newSprite = CreateTile(Resources.Load<Sprite>("Sprites/grass_1"));
for (var i = 0; i < 10; i++)
{
for (var j = 0; i < 10; j++)
{
Instantiate(newSprite, new Vector3(i, j, 0), default(Quaternion));
}
}
}
private GameObject CreateTile(Sprite tileSprite)
{
var newTile = (GameObject) Resources.Load("Tiles/basicTile");
var g = newTile.transform.Find("material").GetComponent<SpriteRenderer>().sprite = tileSprite;
return (GameObject) newTile;
}
}
If I take away the for loop (changing i and j to some integer) I do not have an issue and my object renders just fine. Can anybody explain this to me?
Follow this Question
Related Questions
NullReferenceException: Object reference not set to an instance of an object 3 Answers
Trying to replace 2 objects. Destroying assets is not permitted to avoid data loss. 0 Answers
local scale not working? 2 Answers
Problema al crear objeto por segunda vez. Problem to instantatiate a object for second try. 1 Answer