Question by
MasterMan917 · Oct 17, 2019 at 08:32 PM ·
instantiatememory leak
For Loop With Instantiate Memory Leak
I'm new to C# (3 days) but not to coding, and I'm trying to have a for loop create an object and move it up a unit, but It seems to be crashing unity by using up more and more memory. I don't understand why it's crashing, because if I add a Debug.Log, it shows that the code only runs 10 times like it should. here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CreateAnotherCube : MonoBehaviour
{
public Transform CubePos;
public GameObject CubeSpawn;
void Start()
{
for (int y = 0; y < 10; y++)
{
Instantiate(CubePos, new Vector3(0, y, 0),CubePos.rotation);
}
}
}
Comment
that code wont crash unity, 100% sure, there must be other problem