brentsky96
brentsky96

Reputation: 11

Unity Engine "SendMessage has no receiver" Error

SendMessage ReceiveDamage has no receiver!
UnityEngine.Component:SendMessage (string,object)
Weapon:OnCollide (UnityEngine.Collider2D) (at Assets/Scripts/Weapon.cs:56)
Collidable:Update () (at Assets/Scripts/Collidable.cs:27)
Weapon:Update () (at Assets/Scripts/Weapon.cs:28)

Error Image Weapon Code Part 1 Weapon Code Part 2 Collide Code

I have tried using base.Update(); and just copying and pasting the code but the error still shows up.

I'm very new to game development and can't figure this out.

Upvotes: 0

Views: 4596

Answers (2)

brentsky96
brentsky96

Reputation: 11

I figured it out.... I had put the enemy script on both the enemy and the enemies hitbox, removing it from the hitbox fixed the issue.

Upvotes: 1

KBaker
KBaker

Reputation: 401

This error means that no object is receiving the message you sent, because you are sending it through "coll", which is a Collider2D. You have to send it through the GameObject like this:

coll.gameObject.SendMessage("ReceiveDamage", dmg);

For this to work, the collided GameObject (which in this case is a "Fighter") must have a script attached to it that also has a function called ReceiveDamage.

You can learn more about this here: https://docs.unity3d.com/ScriptReference/GameObject.SendMessage.html

Upvotes: 0

Related Questions