Why are multiple objects being instantiated when I use clone, but not regular instantiation?

For whatever reason the line ‘clone = (BaseGameObject)Instantiate(objectToSpawn, spawnerLocation, Quaternion.identity);’ always spawns multiple objects, while this line only spawns one everytime ‘Instantiate(objectToSpawn, spawnerLocation, Quaternion.identity);’.

If it helps, during runtime I get the error ‘InvalidCastExcept: Cannot cast from source type to destination type.’ on this line;

clone = (BaseGameObject)Instantiate(objectToSpawn, spawnerLocation, Quaternion.identity);


public class ObjectSpawnPoint : BaseGameObject
{
    void Update()
    {
        if( ... ){
            BaseGameObject clone;
            // Spawn multiple objs
            clone = (BaseGameObject)Instantiate(objectToSpawn, 
                                           spawnerLocation, Quaternion.identity);
           // Spawn only one obj
           //Instantiate(objectToSpawn, spawnerLocation, Quaternion.identity);
        }
    }

}

The BaseObjectClass is here

public class BaseGameObject : MonoBehaviour { /*[...]*/ }

[Edit by Berenger : Removed all the unnecessary code. Full text in comments]

You can’t cast Object into a component. You need, first, to cast it into a GameObject with as, and then access the component with GetComponent. I think that’s where you’re error comes from, and I edited the question accordingly. If it is not, well, sorry :slight_smile: but the full code is not lost anyway.