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 BruceT · Apr 27, 2013 at 06:37 AM · errorsendmessageparametersstruct

Using Struct to SendMessage - Number of parameters error.

Hi guys,

I have been reading up on how to send multiple variables with SendMessage. The simplest way that I 'thought' I could understand was using was using a struct.

I have this at just above the void Awake() function...

 public struct ExplosionParameters
 {
  public float explosionForce;
  public float explosionUpForce;
  public Vector3 explosionPosition;
 }


I then try to send a message to the other script...

 hit.gameObject.SendMessage("ExplosionInfo", new ExplosionParameters{ explosionForce = Force, explosionUpForce = UpForce, explosionPosition = transform.position } );

This has 3 Parameters.

The other script has the following void...

 public virtual void ExplosionInfo(float eF, float eUF, Vector3 eP)
 {
  explosionForce = eF;
  explosionUpForce = eUF;
  explosionPosition = eP;
 }

This also has 3 parameters.

But, I am getting the following error...

Failed to call function ExplosionInfo of class vp_DamageHandler Calling function ExplosionInfo with 1 parameter but the function requires 3.

What am I doing wrong?

Many thanks for looking!

Sincerely,

Bruce

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

1 Reply

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

Answer by DannyB · Apr 27, 2013 at 06:44 AM

It would seem that you are trying to send the struct (one parameter) to ExplosionInfo, which expects three parameters.

Try creating a ExplosionInfo( ExplosionParameters info ) method.

Struct example:

 struct MessageInfo {
     public string msg;
     public int number;

     public MessageInfo( string msg, int number ) {
         this.msg = msg; 
         this.number = number;
     }
 }


Send message like this:

 receiver.SendMessage( "GetMessage", new MessageInfo( "Hi", 3 ) );    


Receive the message like this:

 void GetMessage( MessageInfo info ) {
     Debug.Log(info.msg);
     Debug.Log(info.number);
 }
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 BruceT · Apr 27, 2013 at 08:05 AM 0
Share

Hi Danny,

$$anonymous$$any thanks for your response! Have been trying to work out 'ExplosionInfo( ExplosionParameters params )' after I read your response, so am not ignoring you hehe.

So the struct is is seen as one parameter rather than the 3 inside it, that makes sense.

Will keep working away. At the moment it doesn't like the 'params' part but it is highlighted in blue so it defintely recognises it.

Cheers!

avatar image DannyB · Apr 27, 2013 at 08:22 AM 0
Share

Oh, my bad. Just rename "params" to something else. Say "info".

I have updated the answer.

avatar image BruceT · Apr 27, 2013 at 08:44 AM 0
Share

Bingo! Thanks a million Danny! Worked a treat.

avatar image DannyB · Apr 27, 2013 at 08:47 AM 0
Share

Awesome. $$anonymous$$y pleasure.

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

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

Related Questions

Are named parameters supported? 1 Answer

SendMessage with multiple parameters 3 Answers

How to store a Transform[,] grid in an ArrayList? 2 Answers

Parameter doesnt exist 1 Answer

error CS0309: The type `string' must be convertible to `UnityEngine.Object' in order to use it as parameter `T' in the generic type 2 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