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;

public class Road : MonoBehaviour
    public List<Vector3> points = new List<Vector3>();
    public List<GameObject> gameObjects = new List<GameObject>();
    private int count = 0;
    void Start()
    void Update()
            count = points.Count;
            foreach(GameObject g in gameObjects)
            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:

enter image description here

  • \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    May 8, 2019 at 16:53
  • \$\begingroup\$ 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 \$\endgroup\$ May 8, 2019 at 17:13
  • \$\begingroup\$ And there is exactly 2+3+1=6 cubes and created sequentially, why is this happening ? \$\endgroup\$ May 8, 2019 at 17:13

1 Answer 1


Silly mistake :

            GameObject tem = GameObject.CreatePrimitive(PrimitiveType.Cube);
            tem.transform.position = point;

added replacing

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

2 Cubes were created on that line every time.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .