# GameObject not destroyed in ExecuteInEditMode and spooky Instantiating

I was trying to get familiar with Unity's ExecuteInEditMode

Everything is fine it keeps the old object although I have deleted them.

And one more thing, although every-thing (cube) is instantiated is set as child of GameObject script is attached to, they where the other cubes come from?

I have this code:

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

[ExecuteInEditMode]
{
public List<Vector3> points = new List<Vector3>();
public List<GameObject> gameObjects = new List<GameObject>();
private int count = 0;
void Start()
{}
void Update()
{
if(count!=points.Count)
{
count = points.Count;
foreach(GameObject g in gameObjects)
{
DestroyImmediate(g);
}
gameObjects.Clear();
int i = 0;
foreach (Vector3 point in points)
{
Debug.Log(++i + "  " + point);
GameObject tem = Instantiate(GameObject.CreatePrimitive(PrimitiveType.Cube), point, Quaternion.identity);
tem.transform.parent = gameObject.transform;
}
}
}
}


Here is a snap:

• Can you walk us through the sequence of events that leads to these cubes appearing in your scene, starting from a completely empty scene? In particular, call out any steps that cause a serialization/deserialization pass, like saving/opening the scene or entering/exiting play mode. May 8 '19 at 16:53
• It was Unity's SampleScene with camera and Light, then I created an empty GameObject then created the script. After that, set value to 2,3,1 May 8 '19 at 17:13
• And there is exactly 2+3+1=6 cubes and created sequentially, why is this happening ? May 8 '19 at 17:13

            GameObject tem = GameObject.CreatePrimitive(PrimitiveType.Cube);

GameObject tem = Instantiate(GameObject.CreatePrimitive(PrimitiveType.Cube), point, Quaternion.identity);