C# SendMessage to objects in array

So I’ve been pulling out my hairs one by one trying figure this one out. It’s probably quite an obvious mistake, but I can’t seem to find it. I’m trying to send a message to all enemies in the scene from the player when the player dies.

Here are the parts of the player script:

public GameObject[] enemies;

void Awake()
{
   enemies = GameObject.FindGameObjectsWithTag("Enemy");
}

void Respawn()
{
	for (int i=0; i<enemies.Length; i++) 
	{
       enemies*.SendMessage("PlayerDied");*
  • }*
    }
    And the enemy script just has a function called “PlayerDied”, which sets the enemy in a passive state. The problem is, I keep getting the error that says: ‘SendMessage has no receiver!’
    Any help would be appreciated!

try:

enemies*.SendMessage("PlayerDied", SendMessageOptions.DontRequireReceiver);* 

That way if there is other components/scripts that dont’ have that method on them, it won’t throw an error RequireReceiver is the default when not specificied.

Okay, I got it to work. Basically my enemies have multiple child objects on them. They were all tagged with the tag ‘Enemy’. So, instead of calling the PlayerDied() method on a ‘Brain’ child object of the enemy, the method was trying to be called on the enemy parent object, which is just a NavMesh Agent.
All I had to do was to use a different tag on the brain object and search for objects with that tag…

I feel dumb for not realising that.