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
1
Question by gregzo · Dec 15, 2011 at 06:16 PM · broadcastmessagereceiver

BroadcastMessage has no receiver: should I care?

Hi! I have a button, it broadcasts messages to its children, which the user can unparent. If the user is a bit silly, he might hit the button whilst there are no objects to receive the message. Should I prevent the broadcasting if there's no one on the receiving end, or just leave it at that? In other words, check for receivers every time the button is presse,d or allow a useless BroadCastMessage?

Thanks for your advice!

Gregzo

Comment
Add comment · Show 3
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 Lo0NuhtiK · Dec 15, 2011 at 06:20 PM 0
Share

could you just wrap your message stuff in an
if(theres some children or whatever I'm doing here){
   then do what I'm doing;
}
then, if there isn't, it wont.. ??

avatar image gregzo · Dec 15, 2011 at 06:24 PM 0
Share

Sure, but I was wondering if there's a downside to Broadcasting in solitude...

avatar image Lo0NuhtiK · Dec 15, 2011 at 06:27 PM 0
Share

Ah, ok.   

1 Reply

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

Answer by jahroy · Dec 15, 2011 at 06:30 PM

If you look closely at the documentation, you'll notice there's a third parameter, which is a SendMessageOptions argument.

The default value is SendOptions.RequireReceiver, which, according to the documentation, will print an error message if the message is not received by any component.

If you set it to SendOptions.DontRequireReceiver, the error message will not be printed.

I believe the downside to using BroadcastMessage is that it will operate on all children, which may not be super efficient. It probably doesn't matter unless you're doing it every frame.

If the object has no children (or a small number of children) the impact should be nothing (or almost nothing).

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 gregzo · Dec 15, 2011 at 06:34 PM 0
Share

Yep, aware of that, just wondering if there was a downside to a receiverless BroadCast$$anonymous$$essage , because it seems to me all the DontRequireReceiver parameter does is preventing the error message in the console, no?

avatar image jahroy · Dec 15, 2011 at 06:38 PM 2
Share

Yes. $$anonymous$$y answer is my attempt at answering your question. That's all I got.

I think the overhead of Broadcast$$anonymous$$essage is calling it on each component/child of an object.

I think that's all you need to know.

It basically says, here's component A, does it have a function named B? If so, use reflection to call it. If not, move on to the next component.

If you're okay with that, there is no downside.

avatar image gregzo · Dec 15, 2011 at 06:42 PM 0
Share

Cheers, that's exactly what I wanted to know.

avatar image Captain-Awesome · Mar 28, 2015 at 03:22 AM 0
Share

Thanks that helped me too, almost 4 years later.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I send a Transform as parameter with BroadcastMessage()? 1 Answer

BroadcastMessage frustratng problem 1 Answer

UnitySendMessage does and doesn't recognize receiver in 2 similar instances 0 Answers

BroadcastMessage between children? 3 Answers

Setting Text.text in UI efficiency? 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