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
0
Question by James Simpson · Apr 13, 2010 at 08:57 PM · errorsendmessage

SendMessage StartSending has no receiver!

I am trying to call a method of a script attached to a different object. I have the following code, and I've attached the object to the localPlayerObject variable in the inspector, but I am still getting an error saying there is no receiver.

public Transform localPlayerObject;

private void SpawnLocalPlayer() { localPlayerObject.SendMessage("StartSending"); }

I tried Debug.Log(localPlayerObject.name); and it gave me the correct name, so I know I am referencing it correctly. And yes, StartSending is declared in the other script:

void StartSending() {
    sendMode = true;
}
Comment
Add comment · Show 4
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 duck ♦♦ · Apr 13, 2010 at 09:15 PM 0
Share

As far as I can see, what you have - as written - should work. This means the problem must be somewhere else, presumably in how you have your objects and scripts set up in the hierarchy.

$$anonymous$$ake sure:

  • You aren't mixing script types (c# and JS)
  • You have the script containing the "StartSending" method attached to the "localPlayerObject" (not one of its children)

Hm, I've just seen Eric5h5's answer and he's probably right! :-)

avatar image Eric5h5 duck ♦♦ · Apr 13, 2010 at 10:26 PM 0
Share

Actually, mixing script types is a perfect reason to use Send$$anonymous$$essage, as opposed to other ways like GetComponent. Send$$anonymous$$essage is totally runtime so it doesn't depend on compile order at all.

avatar image y0ux · Jun 16, 2012 at 07:32 PM 0
Share

This probably is no necessary any more but here is what I found, having the same problem.

Theory: To send a message you receiver should be in the game object as the one you are sending it. It would look useless but the whole idea is to add scripts to an object without bothering about references, so different script doing different things having a function with the same name can be attached and remove to the same object on different times during runtime. Component.Send$$anonymous$$essage

The problem: Since you are just sending a message but your receiver is in another game object, its impossible for the message to be receive across game objects.

Solutions:

  • having a reference to the object with function you want to send the message to and calling its function directly (as Send$$anonymous$$essage would be pointless)

  • having a father/root in common, taking its reference and using Broadcast$$anonymous$$essage function to call the function, kind of like:

transform.root.Broadcast$$anonymous$$essage("myFunction")

of course this could lead to calling all the functions with that name

  • sort your game objects by purpose nesting into empty GameObjects, having a manager to reference the head of each group and call Broadcast$$anonymous$$essage on each head

  • and... well, thats all that came to my $$anonymous$$d, I used the first solution since it blend well with my problem.

hope this help anyone,

cheers,

avatar image Bunny83 y0ux · Jun 16, 2012 at 07:40 PM 0
Share

First this question is 2 years old and has already been answered...

Second, Your theory is completely wrong :D Since you call the Send$$anonymous$$essage function of another object, the Send$$anonymous$$essage function invokes the function on it's attached $$anonymous$$onoBehaviours. Since the function belongs to the target object (or a component on that object) it doesn't matter who calls the function.

1 Reply

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

Answer by Eric5h5 · Apr 13, 2010 at 09:11 PM

The only way I can see that wouldn't work is if the object you dragged onto the localPlayerObject variable was a prefab instead of an instance of a prefab.

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Attack a Target (using mouse over?) 1 Answer

Getting index of the smallest number in a list 1 Answer

NullReferenceException problem 2 Answers

BCE0049 error with networking script 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