Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Lemo76 · Mar 09, 2013 at 12:17 AM · spawnmessagesendreceiver

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lemo76 · Mar 09, 2013 at 08:34 PM 0
Share

Do I put GetComponent on the one which was sending the message or the one which was receiving?

avatar image Lemo76 · Mar 11, 2013 at 09:48 AM 0
Share

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?

avatar image Kleptomaniac · Mar 11, 2013 at 12:12 PM 1
Share

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. ;)

avatar image Lemo76 · Mar 12, 2013 at 06:44 AM 0
Share

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: alt text

1.png (100.2 kB)
avatar image Kleptomaniac · Mar 12, 2013 at 10:51 AM 0
Share

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

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges