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 BlackWingsCorp · Jan 08, 2013 at 10:49 AM · sendmessagereceiver

SendMessage has no receiver

Hey guys I'm trying to write a script where if the conditions are met it'll send a message to another script attached to an empty GameObject which will instantiate a GameObject (simple right?) Here's the script: function Start () {

 }
 static var targets : int = 0;
 static var haveWon : boolean = false;
 var winSound : AudioClip;
 var cellPrefab : GameObject;
 function Update () {
 if(targets==3 &&haveWon == false){
 targets=0;
 audio.PlayOneShot(winSound);
 haveWon = true;
 cellPrefab.SendMessage("Appear");
 }
 }
 @script RequireComponent(AudioSource)

And here's the empty GameObject's script: var cellHid : GameObject; function Start () { }

 function Update () {
 
 }
 function Appear(){
 Instantiate(cellHid, transform.position, transform.rotation);
 }

The console is telling me that Appear has no receiver, and I'm not sure... well more like I have no idea what to do. So any help will be really appreciated. Thanks.

Comment
Add comment · Show 6
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 AlucardJay · Jan 08, 2013 at 11:04 AM 1
Share

$$anonymous$$ost strange, this should work if your setup is as described. Needless to say, but have you checked that your Appear script is indeed attached to the gameObject cellPrefab?

Create a new scene.

add an empty gameObject, call it Sender, attach this script :

 // Sender
 var cellPrefab : GameObject;
 function Update() 
 {
     if ( Input.Get$$anonymous$$ouseButtonDown(0) ){
         cellPrefab.Send$$anonymous$$essage( "Appear" );
         Debug.Log( gameObject.name + " $$anonymous$$essage Sent ...." );
     }
 }



now add another empty gameObject, call it Receiver, attach this script :

 // Receiver
 function Appear() 
 {
     Debug.Log( gameObject.name + " .... Received message :)" );
 }

Now drop the 'Receiver' object into the 'Sender' inspector, then play the scene. When you left-click the mouse, you should see the Debug messages in the console. This is just a simple test to demonstrate Send$$anonymous$$essage.

avatar image BlackWingsCorp · Jan 08, 2013 at 11:26 AM 0
Share

it is attached to cellPrefab, but didn't quite understand what u meant by "received message" & "message sent" if I may ask

avatar image AlucardJay · Jan 08, 2013 at 11:31 AM 1
Share

I edited my comment, hopefully it makes more sense. But your problem is strange, even if the script with function Appear() was attached to a child of the cellPrefab , Send$$anonymous$$essage would still work. Hence the error has no receiver is implying the gameObject cellPrefab cannot find function Appear() on any script on this object (parent or child). $$anonymous$$ake the test scene, check all is working as it should.

avatar image BlackWingsCorp · Jan 08, 2013 at 11:51 AM 0
Share

well ever heard of unity.3x.developpment essentials? I'm using that ebook to train me on using unity (only ebook that's more than 10 pages) and although I greatly appreciate the authors of the ebook they did a GREAT job, but it needs alot of fixes bcz 1/2 the scripts don't work, great book though, now I have done smthg tht worked I added a new GameObject to the 1st script, if conditions are met the object is instantiated, but it's lower than the floor the player is on. Any idea how to control the Y Axis in Instantiate?

avatar image AlucardJay · Jan 08, 2013 at 11:59 AM 1
Share

Hang on ... so the test worked, and Send$$anonymous$$essage is proven working? You should submit an answer and accept it. The y_instantiate is a new question. But I can cover that here now =]

 Instantiate( object, position : Vector3, rotation : Quaternion);
 Instantiate( cellHid, transform.position, transform.rotation);

So the position of the instantiate is set by a Vector3. You are giving this Vector3 as transform.position. You can adjust this by adding it to another Vector3, eg

 var adjustedPosition : Vector3 = transform.position + Vector3( 0, 0.5, 0 );
 Instantiate( cellHid, adjustedPosition, transform.rotation);

this then adds 0.5 to the Y of the transform.position

IF that book is by Will Goldstone, then yes I have heard of it (though surprised half the code is wrong, unless you are using unity 4.0, then some things changed). In fact, I link his video series to all new users :

Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/essential-skills/

Start at the bottom and work up : http://www.unity3dstudent.com/category/modules/beginner/

this is the YouTube link for the above as one playlist : http://www.youtube.com/watch?v=-oXYHNSmTxg&list=PL27B696FB515608D2&feature=plcp

Edit : the last video is Send$$anonymous$$essage : http://www.unity3dstudent.com/2011/02/beginner-b28-sendmessage-to-call-external-functions/

Show more comments

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

SendMessage handled by one method in different components 1 Answer

C# SendMessage to objects in array 2 Answers

Message sender...how to know who send the 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