Code (CSharp): public GameObject prefab; public int row = 30; [ContextMenu("create prefabs")] public void createprefabs() { for(int i = 0; i < row; i++) { for(int j = 0; j < row; j++) { var g = Instantiate(prefab); g.transform.position = new Vector3(i, 0, j); g.transform.SetParent(transform); } } } very simple code but will crash the project,why>?
You also instantiate, which is quite heavy operation. Set parent will probably force unity will to recalculate all space properties: adjust local position, local rotation and scale, which isn't free. Also, it might depend on your hardware. Anyway, the result is quite expectable, but if you need to actually create 1000 objects, then try to use coroutines. They should probably work in inspector. Just yield return null, after every row.
30*30 objects is 600 objects. That should not in any way crash the project. It might incur a slight lag if the object is complex, but probably not. Is this a crash or a hang? If it's hanging, I suspect an infinite loop - if you call createprefabs from the Start or Awake method of a script attached to the prefab in question, you'd get an infinite loop.
its a crash on i9 9900k 16gbram computer, the code is quite simple like what i post,only instantiate the unity's cube
Where in your code is reference for "transform" ??On line 10 you setting g as it child. Code (CSharp): g.transform.SetParent(transform); You should have reference for it and set it in inspector. Code (CSharp): public Transform transform;
No and same thinkg what is topic about is working fine for me.I instantiating abou 15k objects with same method and it is working fine Code (CSharp): var mineral=Instantiate(CreateMineral(mineralPosition,materialIndex),terrainContainer.transform);
I think yes, it's completley possible, and I wouldn't be so surpired if my Unity crashed after such stress-test.
@Tekrel That's just wrong. You're off by a factor of a million with how much a modern computer should be able to handle. If you copy-paste OP's code and run it, it finishes instantly. If Unity crashed after instantiating less than one thousand objects, it wouldn't be able to load a single scene in a single project we or anyone else made. OP was for sure doing something busted.