IEnumerator AddRemoveAtRuntime() { while (true) { // Loop through primitives foreach (PrimitiveType primitiveType in Enum.GetValues(typeof(PrimitiveType))) { yield return(new WaitForSeconds(3)); // Remove runtime generated prototype definition GPUInstancerAPI.RemovePrototypeAtRuntime(prefabManager, prototype); // Clear the instances ClearInstances(); yield return(new WaitForSeconds(1)); // Create a GameObject to create a prototype from prototypeGameObject = GameObject.CreatePrimitive(primitiveType); // Set material of the GameObject SetMaterial(); // Add the original to the instanceList instanceList.Add(prototypeGameObject); // Define the prototype prototype = GPUInstancerAPI.DefineGameObjectAsPrefabPrototypeAtRuntime(prefabManager, prototypeGameObject); // Create 1000 new instances for (int i = 0; i < 1000; i++) { instanceList.Add(Instantiate(prototypeGameObject, UnityEngine.Random.insideUnitSphere * 20, Quaternion.identity)); } // Add instances to manager GPUInstancerAPI.AddInstancesToPrefabPrototypeAtRuntime(prefabManager, prototype, instanceList); yield return(new WaitForSeconds(1)); } } }