Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Sinncere · Apr 29, 2010 at 02:51 PM · sendmessagemessagesendreceiver

How do i Specify a Receiver for a Send Message Function?

Help! i am not looking to use: SendMessageOptions.DontRequireReceiver.

I have looked up on this in the script reference and the forums. I'm wondering how i would be able specifically give an game-object/script-function a reciever so the messages dosent relay anywhere else.

So far when i use: SendMessageOptions.RequireReceiver i get a dubug log saying e.g no receiver found, how can i get the sendmessage to get picked up by a component? whats the correct way to use SendMessageOptions.RequireReceiver. Thank you.

Antione.

Comment
Add comment · Show 1
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 spinaljack · Apr 29, 2010 at 03:40 PM 0
Share

If you only want to call a method in one script what's stopping you from using GetComponent?

2 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Molix · Apr 29, 2010 at 03:47 PM

SendMessage is a way of broadcasting a message to "anyone that is listening". The option RequireReceiver just lets you know (via an error) if "no one was listening".

If you want to send the message to a specific recipient, you can just get a reference to it (e.g. via GetComponent) and call it. e.g. (C#):

Instead of:

SendMessage("MyFunction");

You'd do:

MyScript myScript = GetComponent(typeof(MyScript)) as MyScript;
myScript.MyFunction();

The JS version is very similar:

var myScript : MyScript= GetComponent(MyScript);
myScript.MyFunction();
Comment
Add comment · Show 4 · 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 Sinncere · Apr 29, 2010 at 04:06 PM 0
Share

Ah yes i see, thanks. Nice one thanks for the quick reply too, im going to test it now, but i will have to translate it to javascript.

avatar image user-3230 (google) · Jun 25, 2010 at 05:56 PM 0
Share

could you post it on here the java translated one please it would help alot

avatar image Molix · Jun 25, 2010 at 09:09 PM 0
Share

JS version added above.

avatar image rm-square · Aug 25, 2015 at 07:20 PM 0
Share

We should explain, that "anyone that is listening" means any Component, that is attached to the GameObject. So for example, if you want every Unit to attack a base, you can't simply call Send$$anonymous$$essage("attackEnemyBase").

avatar image
0

Answer by Sinncere · Apr 29, 2010 at 04:20 PM

Component.GetComponent

Thanks agen just saw this in the script reference, in any case others are intrested.

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Send Message Has no Receiver 1 Answer

SendMessage , how can i send two parameter 3 Answers

Message not being recieved 1 Answer

Collision script 1 Answer

GameObject not Scaling Correctly after Receiving Message 1 Answer


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