Retrieve the exact spawn point when I destroy its pickup

Hi everyone I have a little problem here, I have already checked here and on google but nothing seems to help to solve my problem so here we are, I have a list of spawn points

spawnPointList = new List<SpawnPoint>();

and I have 3 classes (pickup controller, spawn point and player controller).

Inside the class pickup controller I instantiate for every spawn point a pickup and i set the availability as false:

void Start()
		//spawn the first pickups on every spawnPoint and after set them unavailable
		foreach (SpawnPoint spawn in spawnPointList) 
			spawn.available = false;

As you can see I have an ID for every spawn point (3 spawn point at the moment).

Inside the Player controller I check if I collided with a pick up and from the same function i set some needed data in the pickup controller:

void OnControllerColliderHit (ControllerColliderHit hit)
		if (hit.gameObject.tag == "Pickup")
			Pickup_controller.collision = true;
			Pickup_controller.object_hit = hit.gameObject;

After that, in the pickup controller update, I call the function that destroy the pickup:

void Update()
		SpawnPoint spawn = spawnPointList.Find (x => x);
		//on collision with a pick up we destroy it and spawn another one on that spawn point after a while
		if (Pickup_controller.collision == true) 
			//this is the function that delete the pick up

			time -= (Time.deltaTime / Time.deltaTime);
			if (spawn.available == true)
				if(time < 0)

Well now the problem is: I can’t just disable the pickup to enable it back later, I really have to destroy it and place another NEW one in the empty spawn point but from here I don’t know how to retrieve the empty spawn point after i destroy the pick up.

Already tried to save the pickup in another Game object calling the delete function delete the copy too.

The problem isn’t the pickup (because in the future I have to take the pickup and put into inventory so have to left the scene) the problem is how to retrieve the exact empty spawn point in the list after i destroy “its” pick up.

I create a public ID component for every spawn point thinking it might come in handy.

Thank you in advance.

PS.: Right now (clearly) in the pickup controller update function after the delete of the pickup, and after a while, a new pickup is spawned on the empty spawn point but doesn’t work because after the start function in pickup controller the availability remain false.

You can set the pickup to enabled again, it just has to be done from a separate object. Each time you create an object to be disabled, register it with a higher up parent, and when it needs to be enabled again, signal it through the parent.

Then it is simply a matter of

parent.childSpawn[x].enabled=true; // childSpawn is a variable of type scriptComponent you wish to set

To get the proper spawn point, you must have the object you pickup ‘send’ its ‘spawn point’ back to the controller. I have just implemented this in my project. You need to study more about utilizing your variables on Instantiation. Right when you spawn something, boom, you should be setting the parent into the object being spawned. Then when its time, the object sends its parent back to the controller as a variable within a function, boom, gone.

Your answers lie within, good luck

I already did a thing like parenting the pickup with its spawnpoint:

public void SpawnPickup(int id){

            //the number of spawn points in the list
            numberOfSpawnPoints = spawnPointList.Count;
		//if the number of pickup are higher then number of spawn point the number of pickup will be the exact number of spawn point
		if (Pickup_controller.instance.numberOfPickups > numberOfSpawnPoints)
			numberOfPickups = numberOfSpawnPoints;


		//retrieve the position of the pickup spawn point
		Vector3 spawnedPickupPosition = spawnPointList.Find (x => x.IdTrue(id)).transform.position;
		Quaternion spawnedPickupRotation = spawnPointList.Find (x => x.IdTrue(id)).transform.rotation;

		//instatiate the pickup with the above postion and rotation
		GameObject spawnedPickup = GameObject.Instantiate(instance.pickup_prefab, spawnedPickupPosition, spawnedPickupRotation) as GameObject;
		spawnedPickup.transform.parent = instance.spawnPointList.Find (x => x.IdTrue(id)).transform;

But I call this function in the “start” to spawn the first pickups then I call it again in the update, clearly this function (SpawnPickup) spawn a pickup on a spawnpoint, so I don’t know how to retrieve the empty spawnpoint also if I have parented every single pickups to every single spawnpoint, I mean you said to “send” its “spawnpoint” back to the controller, ok, but from the piece of code above can you tell me what is missing to save this data somewhere?

When the game start I spawn not the original pickup but its clones, so every spawnpoint have a clone of the pickup, after that as I said before i don’t want (if possible) to enable the pickups and disable them when i “interact” with them and enbale again after a while, i need to destroy the pickup, it need to left the scene completly.

Thank you for the answer probably this is the solution :slight_smile: