SetActive = false on previous instantiated prefab

I am using the following code to create a line of prefabs

{
 
 public GameObject myPrefab;
 
 Vector3 lastPosition = new Vector3(0,2,0);
 Vector3 offsetVector = new Vector3(0,0,-3);

 void Update()
 {
     if(Input.GetKeyDown (KeyCode.Space))
     {
     GameObject myPrefabInstance = GameObject.Instantiate(myPrefab, lastPosition + offsetVector, Quaternion.identity);
     lastPosition = myPrefabInstance.transform.position;
     }
 }
}

This works great and gives me a nice even row of prefabs. However I want the player to be able to adjust the position of each prefab once it is placed and have an arrow key move script attached to the parent prefab. Of course this means that currently all the prefabs move in unison. How do I disable the previous prefab (perhaps with SetActive = false) once the space bar is pressed and the next prefab is placed. Currently I only want the player to be able to move each prefab once.

Thanks for any suggestions.

You could save the myPrefabInstance as a global GameObject. Each time the Space bar is pressed down, the variable will be overwritten to the newly created gameobject. You then use your movement script on that saved gameobject. When the space bar is pressed again, the new gameobject is assigned to the variable and can be controlled using your script.

@metalted OK, bear with me, I’m a relative noob. I get what you’re saying in principle but haven’t been able to find an example of this by searching “save prefab instance as global GameObject”. Is there another way to phrase this that will help me find some pointers? Thanks.