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 boymeetsrobot · Oct 24, 2010 at 08:49 PM · eventsendmessagebroadcastmessage

Sending and Receiving Messages globally with BroadcastMessage / SendMessage

Hi all.

Looking at BroadcastMessage and SendMessage it appears that only the GameObject or its children can receive the messages. I wish to have a single Event Gameobject in the scene sending messages at intervals. I would like any objects active in the scene to be able to subscribe or "listen" to these messages. Is this possible?

I really like how event bubbling works in Actionscript 3 and would like to mimic this in Unity.

Thanks,

Dave

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

4 Replies

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

Answer by boymeetsrobot · Oct 26, 2010 at 07:36 AM

Thanks for the response.

I have found that there are a few event managers that have been written by the community which are a great starting block for writing decoupled code. I would advise to anyone serious about using Unity to look at using these methods of programming as oppose to relying on the hierarchy limitation of the BroadcastMessage approach. In an ideal world, an object should not worry about who is receiving its events or whether it has a relationship or a reference to another object. This leads to code that is not reusable and difficult to debug.

There is an excellent video on the subject by Mike Mittelman of Hangout Industries from Unite 2008 that can be found on Unity3d.com http://unity3d.com/support/resources/unite-presentations/techniques-for-making-reusable-code

Additionally, here is a link to a great Unity forum post that has a few event manager links in it. http://forum.unity3d.com/threads/37896-Programming-architectures I am currently using the iPhone friendly NotificationCenter class by Prime31 and it works in a similar way to the Actionscript 3 event model.

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
avatar image
1

Answer by Eric5h5 · Oct 24, 2010 at 08:54 PM

A simple way is to make an empty gameobject and have all gameobjects that should receive messages be a child of this empty. Then use BroadcastMessage on the empty.

Comment
Add comment · Show 1 · 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 flamy · Jan 11, 2012 at 11:40 AM 0
Share

wont it cause an extra matrix calculation whn the object moves or rotates??

avatar image
0

Answer by Ghopper21 · Oct 16, 2012 at 10:38 PM

Check out this type-safe event management system by Will Miller.

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
avatar image
0

Answer by dustinandrew · Oct 31, 2012 at 09:30 PM

Event Manager for Unity A static manager for handling an event driven communication model in Unity. This is similar to Adobe Flash's event listener model used in ActionScript.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

once again, Sendmessage VS Getcomponent! 1 Answer

SendMessage is running before Start 1 Answer

SendMessage and BroadcastMessage not getting received outside the script. 0 Answers

How can I Broadcast a message on a GameObject and also send the message Upwards natively without sending twice the message on the target base object? 0 Answers

BroadcastMessage Functionality Help 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