Missing objects upon List.Add();

Basically I have a list in which i need to get instances of a prefab. I instantiate them by using [ExecuteInEditMode]

Here’s the line i’m using to instantiate it:

enemyArray  *= (GameObject)Instantiate (enemy, spawnPosition, Quaternion.Euler (0, 0, 0));*

The problem is, when i try to add this gameobject to a list using Add(), i simply get lots of these “Missing GameObject” in the inspector, and i have created the list as new List() alongside declaring it aswell. I try to add them using foreach loop:
foreach(Transform enemy in transform)
{

  • Debug.Log (enemy.name);*
  • enemies.Add (enemy.gameObject);*
    }
    Weird thing is, it actually debugs the names of the objects correctly. And another weird thing is if i just drag and drop this prefab into the scene, the Add() function will work, it simply won’t work on the instances.
    If anyone can tell me why it’s happening this way, I will really appreciate it. Thanks.

Why use ExecuteInEditMode? Have you tried not using it?

Why did you not post this as a solution?... Scrub.

1 Answer

1

For your usage scenario, i would use Gizmos.

You can assign custom meshes to them, and they only draw in the Editor. This is what you are looking for :smiley:

This works. Thanks.