- Home /
Send Message Has no Receiver
So this is a part of a script I have attached to a wall:
SendMessage("Cubelimit");
Then this is the script attatched to the prefab of the cubes spawning from the wall when I shoot the wall:
function Cubelimit () {
print ("spawned!"); }
It seems to say 'Send Message Cube Limit has no reciever. Can you figure out what the problem is from this?
Answer by $$anonymous$$ · Mar 09, 2013 at 01:09 AM
The sendMessage()
function only works with scripts attached to the same gameObject, try GetComponent instead
Do I put GetComponent on the one which was sending the message or the one which was receiving?
So I have: var destroytokenscript : destroy token;
destroytokenscript = GetComponent("destroy token"); Note: destroy token is the name of the other script.
It seems to always bug me by saying that the var destroytokenscript : destroy token; needs a semicolon at the end when there clearly is. Why is it doing this?
A class name can not be contain a [space] character in it (as far as I know), so therefore I heavily doubt the name of your other script is 'destroy token'. Type it exactly as it is, for example:
var destroyTokenScript : DestroyToken;
Also, in order to call a component on another object, you need to specify the object.
Overall, the way you would want to format it would be:
var destroyTokenObj : GameObject; //Attach the object on which DestroyToken is a component through Inspector
private var destroyTokenScript : DestroyToken; //If that is actually your script name
function Start () { //Store your script reference in Start to save on performance overhead
destroyTokenScript = destroyTokenObj.GetComponent(destroyTokenScript); //Also, don't use string lookups - they can also be costly
}
Hope that helps you out, $$anonymous$$lep
PS: As an added note, Ben Jarrell, I'm quite sure you actually can call Send$$anonymous$$essage() on other objects, simply by specifying it as otherObj.Send$$anonymous$$essage(). Overall though, GetComponent is faster performance-wise, as is seen here from Eric5h5: "GetComponent is somewhat faster than Send$$anonymous$$essage". Anyway, that's just my two cents. ;)
Thanks but I still get that error and it is typed up exactly as destroy token. Here is a screenshot to help you help me:
Hey there, the reason this is still not working is because, while script file names are allowed to have spaces, the name of the class is the same but will all spaces removed.
So, in your case, while the name of your script is "destroy token", the name of your class would be "destroytoken". ;)
In future, I would suggest na$$anonymous$$g your scripts in the PascalCase format, i.e. DestroyToken, with no spaces, as this can prevent such ambiguity with class inheritance. :)
$$anonymous$$lep
Your answer
Follow this Question
Related Questions
How do i Specify a Receiver for a Send Message Function? 2 Answers
SendMessage , how can i send two parameter 3 Answers
How to Send Message to other GameObject 3 Answers
Receiving windows message in Unity 0 Answers
Animation Event for different objects 0 Answers