Respawn not working past 2nd respawn

Hey all,

I’m attempting to respawn an object in it’s original spot once it’s destroyed. It seems to work the first time but it’s not working past that. I see what’s going on, for some reason the clone does not have the objects I’ve attached to the original objects script.

For a little context, I’m dragging this object onto a character. Once it hits him I want the object to be destroyed and a replacement to respawn in the objects original place.

Is there something I need to do to ensure the clones call these objects? I’ve attached my code below.

public GameObject fishFood; //= GameObject.Find ("Food");
public Transform fishFoodSpawn;
public Vector2 spawnLocation = new Vector3 (-3.88f, 2.44f, 0f);
private bool dragging = false;
private float distance;



void OnMouseDown()
{
	distance = Vector2.Distance(transform.position, Camera.main.transform.position);
	dragging = true;
}

void OnMouseUp()
{
	dragging = false;
}

void Update()
{
	if (dragging)
	{
		Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		Vector2 rayPoint = ray.GetPoint(distance);
		transform.position = rayPoint;
	}
}

// Destroy the food once it enters the bears mouth area
void OnTriggerEnter2D (Collider2D other)
{
	if (other.tag == "Bear")
		Destroy (gameObject);

}

void OnDestroy() {
	Instantiate (fishFood, spawnLocation, Quaternion.identity);
}

}

Thanks in advance!

@maydaywray , Actually, since you don’t have a set wait time between each respawn, a cleaner way would be to simply to move the transform of the your GameObject back to the spawn transform, like so

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour {

	public Transform fishFoodSpawn;
	
	//Declare other variables
	
	//Put other functions here
	
	void OnTriggerEnter2D (Collider2D other) {
		if(other.tag == "Bear")
			Respawn();
	}
	
	void Respawn () {
		gameObject.transform.position = fishFoodSpawn.position;
		Debug.Log("You Died");
	}
}

I tested this and it seems to work for me, but in case you have a Rigidbody attached to this GameObject you may want to store a reference to said Rigidbody and then set velocity to 0. I hope this helps!