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 rajat · Mar 26, 2013 at 08:54 PM · sendmessagebroadcastmessage

SendMessage and BroadcastMessage not getting received outside the script.

I have a gameobject named Camerascript which contains two scripts, script1.cs and script2.cs

script2.cs has this line

      BroadcastMessage("HandRaiseDetector_HandRaise", joint, SendMessageOptions.DontRequireReceiver);

script1.cs has this function

 void HandRaiseDetector_HandRaise(ZigJointId zig)
     {
     Debug.Log("Hand Raised camera change");    
     }

but this function never gets called.However,if i place this function inside script2.cs it gets called. Same is the case if i use sendmessage instead of broadcast message why is the function not getting called in script1.cs.

Comment
Add comment · Show 5
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 iwaldrop · Mar 27, 2013 at 12:29 AM 0
Share

A few thoughts/questions:

  • Are you positive that script1.cs is attached to the GameObject?

  • Is there a reason that there are two scripts; in other words, can you combine them and simply perform a method call?

  • Have you thought about using a Delegate and Event ins$$anonymous$$d of Send$$anonymous$$essage?

From what I'm reading of your architecture both Send$$anonymous$$essage() and Broadcase$$anonymous$$essage() should work; both scripts appear to be on the same GameObject. If that's the case then its very strange that it wouldn't work, and I'd file a bug report with Unity. But because it would be so strange I would first assume that you've configured something incorrectly with your scripts/gameObject.

avatar image rajat · Mar 27, 2013 at 07:03 AM 0
Share
  • I am 100% positive that script1.cs and script2.cs are attached to the same gameobject.

  • Yes, the reason is one of the script is from a library which performs just the function of sending various messages , i don't want to mix and mess it up.

  • No i haven't, but i will now. Thanks.

Do i need to provide a listener or something in scrpit1.cs for receiving the message, i just have the HandRaiseDetector_HandRaise function there.

avatar image iwaldrop · Mar 27, 2013 at 02:48 PM 0
Share

The existing method would works as a handler; you just need to attach to it in Start/Awake and detach in OnDestroy or somewhere suitable to your needs.

avatar image rajat · Mar 27, 2013 at 02:53 PM 0
Share

I don't understand. How do i attach to it in Start. BTW delegate and event work as expected :), Thanks.

avatar image iwaldrop · Mar 27, 2013 at 03:09 PM 0
Share

Sorry if I confused you. I'm typing on my phone so it's easy to make silly mistakes. What I meant was attach to the event on start or awake, but it seems like you got it working already so ignore that comment! :)

0 Replies

· Add your reply
  • Sort: 

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

Passing 'null' as parameter to SendMessage/BroadcastMessage 2 Answers

BroadcastMessage from one Object to another ? 1 Answer

Sending and Receiving Messages globally with BroadcastMessage / SendMessage 4 Answers

SendMessage is running before Start 1 Answer

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


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