how do i remember a just instantiated prefab as a variable gameobject?

i want to assign a gameobject to my just instantiated prefab.
the problem is. it needs to change depending on what lane the prefab spawned on. (each prefab needs to remember the object that spawned the prefab)
i have tried this:

GameObject MonsterInstance = Instantiate(PrefabGreenMonster, SpawnPoint.position, SpawnPoint.rotation) as GameObject;
MonsterInstance.GetComponent<WalkingScript>().Target_LaneController = gameObject;

but sadly, for some reason i cant get it to work.

i need to find a way to send something to the instantiated prefab.

Let’s see if I got you right on this.

you could have your Script_A like this:

public class Script_A : NetworkBehaviour {
public int number=5;
void Start(){
 GameObject o = Instantiate(Prefab,Position,Rotation) as GameObject;

Now your Script_B Needs a global(public) Variable of Type Script_A (in my example it has the Name “scriptA” so Script_A can link itself (with “this”) to Script_B. Now after the new GameObject with Script_B attached has been spawned it can Access all global (public) Variables of Script_A:

public class Script_B : NetworkBehaviour{
 public Script_A scriptA;
 void Start(){

Now your Script_B should print out the number 5 of Script_A