Unity – Why, when using an object pool to randomly instantiate objects, does this sometimes show less hierarchy to 1000 objects?

And if I set the spin speed to full speed, I can not click in the scene window on objects that are rotating. If I put the mouse of objects / s in the hierarchy, they turn faster but if I put the mouse on the window of the scene, they turn more slowly.

This does not seem to work too well with the object pool.

I first tried to also use ExecuteInEditMode but it made things a lot more complicated so I left it for now.

using System.Collections;
using System.Collections.Generic;
use UnityEngine;

//[ExecuteInEditMode]
Public class InstantiateObjects: MonoBehaviour
{
Prefabricated public GameObject;
public land;
floating public yOffset = 0.5f;
    [Range(10, 1000)]
    public int objectAmount;
public bool randomScale = false;
public bool randomRotation = false;
    [Range(1, 100)]
    public float rate = 50;
public bool spinPbjects = false;
public bool parent = true;
public string parentName;
public bool addNewAtStart = false;

public Vector3 RandScaleMin;
public Vector3 RandScaleMax;

    [Range(0, 360)]
    public float randomRotationX;
    [Range(0, 360)]
    public float randomRotationY;
    [Range(0, 360)]
    public float randomRotationZ;

private float terrainWidth;
private float terrainLength;
private float xTerrainPos;
private float zTerrainPos;
private GameObject clonedObject;
private ObjectPool objectPool;
private int amount = 0;
Private GameObject[] cloned objects;

public void Start ()
{
// Get the size of the field
terrainWidth = terrain.terrainData.size.x;
terrainLength = terrain.terrainData.size.z;

// Get the position of the field
xTerrainPos = terrain.transform.position.x;
zTerrainPos = terrain.transform.position.z;

quantity = objectsAmount;

objectPool = new ObjectPool (prefab, objectsAmount);

// if (Application.isPlaying == true && addNewAtStart == true)
// {
generateObjectOnTerrain ();
clonedobjects = GameObject.FindGameObjectsWithTag ("Cloned");
if (clonedobjects.Length> 0)
{
objectsAmount = clonedobjects.Length;
quantity = objectsAmount;
}
//}
}

Empty public update ()
{
if (number of objects> amount)
{
generateObjectOnTerrain ();
quantity = objectsAmount;
clonedobjects = GameObject.FindGameObjectsWithTag ("Cloned");
}

if (number of objects <amount)
{
ReleaseObjects ();
quantity = objectsAmount;
clonedobjects = GameObject.FindGameObjectsWithTag ("Cloned");
}

if (spinPbjects == true)
{
if (clonedobjects! = null)
{
for (int i = 0; i <clonedobjects.Length; i ++)
{
cloned objects[i].transform.Rotate (Vector3.left, 45 * Time.deltaTime * spinSpeed);
}
}
}
}

public void ReleaseObjects ()
{
GameObject[] allobj = GameObject.FindGameObjectsWithTag ("Cloned");
for (var i = 0; i <allobj.Length; i ++)
{
objectPool.ReturnInstance (allobj[i])
ALLOBJ[i].hideFlags = HideFlags.HideInHierarchy;
}
generateObjectOnTerrain ();
}

public void generateObjectOnTerrain ()
{
for (int i = 0; i <objectsAmount; i ++)
{
// Generate random positions x, z, y in the field
float randX = UnityEngine.Random.Range (xTerrainPos, xTerrainPos + terrainWidth);
float randZ = UnityEngine.Random.Range (zTerrainPos, zTerrainPos + terrainLength);

float yVal = Terrain.active Terrain.SampleHeight (new Vector3 (randX, 0, randZ));

var randScaleX = Random.Range (RandScaleMin.x, RandScaleMax.x);
var randScaleY = Random.Range (RandScaleMin.y, RandScaleMax.y);
var randScaleZ = Random.Range (RandScaleMin.z, RandScaleMax.z);
var randVector3 = new Vector3 (randScaleX, randScaleY, randScaleZ);

var randRotX = Random.Range (0, randomRotationX);
var randRotY = Random.Range (0, randomRotationY);
var randRotZ = Random.Range (0, randomRotationZ);
var randRotation = Quaternion.Euler (randRotX, randRotY, randRotZ);

// Apply an offset if necessary
yVal = yVal + yOffset;

clonedObject = objectPool.GtInstance ();

clonedObject.tag = "Cloned";

if (randomScale == true)
{
clonedObject.transform.localScale = randVector3; // new Vector3 (randScaleX, randScaleY, randScaleZ);
}

if (randomRotation == true)
{
clonedObject.transform.rotation = randRotation;
}

if (parent)
{
if (parentName! = null && parentName! = "")
{
GameObject parent = GameObject.Find (parentName);
clonedObject.transform.parent = parent.transform;
}
other
{
clonedObject.transform.parent = gameObject.transform;
}
}

clonedObject.transform.position = new Vector3 (randX, yVal, randZ);
}
}
}

And the pool of objects:

use UnityEngine;
using System.Collections.Generic;

Public class ObjectPool
{
prefabricated private GameObject;
private list basin;

public ObjectPool (prefabricated GameObject, int initialSize)
{
this.prefab = prefab;

this.pool = new list();
for (int i = 0; i <initial size; i ++)
{
AllocateInstance ();
}
}

public GameObject GtInstance ()
{
if (pool.Count == 0)
{
AllocateInstance ();
}

int lastIndex = pool.Count - 1;
Instance of GameObject = pool[lastIndex];
pool.RemoveAt (lastIndex);

instance.SetActive (true);
return instance;
}

public void ReturnInstance (GameObject instance)
{
instance.SetActive (false);
pool.Add (instance);
}

GameObject Protected Virtual AllocateInstance ()
{
Instance of GameObject = (GameObject) GameObject.Instantiate (prefab);
instance.SetActive (false);
pool.Add (instance);

return instance;
}
}

I use the Range slider to change the amount of objects and the speed of rotation, but it seems that the operation is not as fluid and fast as for pooling. Do not show the actual amount of real-time objects in the hierarchy when the amount of the range is 1,000, sometimes I see 1,000 objects in the hierarchy, sometimes less.

The idea is to change the amount to set new objects randomly if fewer or more objects.