Can't find gameobjects being spawned getting a nullreferenceexception

I’m trying to call a function in a script attached to a gameobject being spawned but it can’t find the object.
Here’s the script:

void OnTriggerEnter2D (Collider2D col) 
	GameObject Bugspawn = GameObject.Find ("BugbotPrefab");
	Transform BugbotTransform = Bugspawn.transform;
	// get player position
	Vector3 bugbotxposition = BugbotTransform.position;

	// If it hits an enemy...
	if (col.tag == "Enemy") {

		col.gameObject.GetComponent<Bugbot>().HP -= 2;

		if (gameObject.transform.position.x > bugbotxposition.x){
		if (gameObject.transform.position.x < bugbotxposition.x){


If I leave the enemy on the scene the script works fine but when I use spawners it can’t find the object for some reason.

here’s the error:
NullReferenceException: Object reference not set to an instance of an object
Swatter.OnTriggerEnter2D (UnityEngine.Collider2D col) (at Assets/Scripts/Swatter.cs:20)
line 20 is Transform BugbotTransform = Bugspawn.transform; but the debug already returns null.

Hi, you should rethink your logic and code structure.
What is the purpose of finding the go by findbytag, if you are finding it
with trigger anyway? Im writing from phone ill be at the office after about 20 mins, ill write you the code.