Instantiated prefabs acting different than those dragged onto scene

I have some prefabs that, when instantiated, act differently than ones that I just place into the scene manually (which perform exactly as intended). Some people have said that it might have something to do with the code that instantiated the objects, so I’ve included some pictures of that. Just in case it helps, my game is in 2D.

Thanks in advance :slight_smile:

First pic:

Second Pic:

If u instantiate multiple of the same thing and there all using the same script then one command will happen to all of them unless you put ‘this.’ Before each line. I.e. this.astroidtype = random.range(0, 4);

Hello @clonetrooper2021

Your posted code is not related with the acting of the asteroids. This code only Instantiate them, only spawns them in the scene.

The code that makes the asteroids do things, i supose is placed inside the asteroids itself.

One thing you can do when instantiating is to give “orders” or assign variables to the just new instantiated object.

You are doing this:

Instatiate (Object, pos, rotation);

But, if you do this (imagine the asteroids prefab have a script component called “MovingAsteroid.cs”) :

GameObject NewAsteroid;
NewAsteroid = Instantiate (AsteroidPrefab, position, rotation);
NewAsteroid.GetComponent<MovingAsteroid>().SomeVariable = 4;

So, I access the just instantiated object the same frame is instantiated, and only that object. Its like the “Start” funcion but executed from outside.

So, if you are having problems with you asteroids, try to force this way the thigs they do when spawned