- Home /
SendMessage has no receiver
hi i get an error on my c# script "SendMessage GetSpeed has no receiver"
gameObject.SendMessage ("GetSpeed", dir);
here is my receiver void GetSpeed(Vector3 thespeed) { speed= thespeed.magnitude;
}// GetSpeed
the strange thing is that the function receives the call and works fine. any ideas on that?
Guess you are also calling it on something that doesn't have that receiver...
Add options to your sendmessage Send$$anonymous$$essageOptions.DontRequireReceiver.
@Crazydadz: That's not a great solution. There's a reason why the default option is require receiver. If you send a message it has a purpose. If you get this error that means something is wrong. Using DontRequireReceiver just suppress the error.
DontRequireReciever is not about suppressing an error. You may (or may not) have object which have receivers. Example: if you have an 'Explode' function on some objects, and not others, but you instantiate them and parent them under some container like 'pinata'. Then Send or Broadcast message to those things which may or may not have 'Explode on them, by design. Because some things explode, some do not, and you may not know at that point which do or do not.
I don't know how I can put this any differently.
You have a component which is working - that has a receiver
You must have another instance where there is not a receiver or the message would not show up.
The reason it works when you take it out of Update is that you are not calling the function that it then resides in, or you are adding the receiver component after the first call to Update.
Answer by DaveA · May 07, 2013 at 11:35 PM
Try BroadcastMessage. My guess is you're sending to the parent of the object where your script actually is?
Your answer
Follow this Question
Related Questions
Assets/Scripts/GameManager.cs(24,33): error CS0029: Cannot implicitly convert type `bool' to `int' 0 Answers
Versy confusing argumentoutofrangeexception error 1 Answer
'invalid generated path' when I create a new file 1 Answer
Can't Get animation.Play to work 0 Answers
I am not able to start unity as I am getting this error before opening the unity 0 Answers