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 Superwayne · May 11, 2013 at 07:50 PM · missingmethodexception

How to fix this "MissingMethodException"

I got 2 Scripts (one on my player GameObject and one on a shoppingNPC GameObject). I have the same class to store some properties declared in bot scripts:

 [System.Serializable]
 public class Item{
     public string name;
     public int costs;
     public float _value;
     public string itemClass;
     public int slotNumber;
     public Texture2D texture;
 }

In my "Inventory" script (the one on the player) i have a function to buy an item which takes "Item _item" as a paramater. I want to call this function from the other script via "SendMessage".

This is the function in the inventory script:

 void BuyItem(Item _item){
         if(_item.costs < rubyAmount){
             
         }
         else{
             infoText.SendMessage("ShowText", "I need more Rubys...");
         }
     }

This is the function with the SendMessage:

     void OnGUI(){
         if(shopActive){
             GUI.skin = shopSkin;
             GUI.BeginGroup(menuAreaNormalized);
             int buttonNumber = 0;
             
             for(int i = 0; i < _itemClass.Length; i++){
                 for(int k = 0; k < _itemClass[i].buyableItem.Length; k++){
                     if(_itemClass[i].buyableItem[k].buyable){
                         if(GUI.Button(new Rect(firstButton.x,firstButton.y + 48 * buttonNumber, firstButton.width, firstButton.height), _itemClass[i].buyableItem[k].itemGUI)){
                             Debug.Log("Classnummer: " + i.ToString() + "; Itemnummer: " + k.ToString() + " pressed");
                             player.SendMessage("BuyItem", _itemClass[i].buyableItem[k]._item);
                         }
                         buttonNumber++;
                     }
                 }
             }
             GUI.EndGroup();
         }
     }

_itemClass is an class storing the className and the item to buy. buyableItem is a class which stores all information needed to buy the item in the shop including the _item of type "Item" (the class from the beginning).

I can't find an error but if I click on an item in the shop it says "MissingMethodException: The best match for method has some invalid parameter."

Anyone can help me?

Comment
Add comment · Show 2
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 kromenak · May 11, 2013 at 08:24 PM 0
Share

I'm not totally sure what the issue is; I see you call player.Send$$anonymous$$essage; is "player" a GameObject, $$anonymous$$onobehavior, or what? For Send$$anonymous$$essage to work, the Inventory component needs to be on the same GameObject as "player". If it is a child or something, you should use Broadcast$$anonymous$$essage.

I'm not much of a fan of Send$$anonymous$$essage because you don't know if it will work until runtime; since you already have the "player" object, my preferred calling method would be something like this:

 Inventory inv = player.GetComponent<Inventory>();
 if(inv != null)
 {
     inv.BuyItem(_itemClass[i].buyableItem[k]._item);
 }

So, I guess my solution would be to fix your Send$$anonymous$$essage problem by not using Send$$anonymous$$essage ;).

avatar image Yarbius · Mar 13, 2015 at 05:27 PM 0
Share

I had a similar issue in my project and the issue turned out to be ambiguity with the method name of a public method in another manager class. Both Classes had a Load$$anonymous$$ap() method and changing the name of the notification was the only way I could get rid of the error

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · May 11, 2013 at 09:26 PM

This error means that you're calling a function with the wrong type or number of arguments. Take a look at the line where the error occurs and check the function calls to find which one has an incompatible argument.

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 Superwayne · May 12, 2013 at 08:45 AM 0
Share

Hmm I already checked it some times but haven't found the issue. I guess the problem is that the "Item" class which I am using as a parameter isn't accepted. I just declared the same "Item" class in both scripts but it seems that it has to be exactly the same class..

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

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

Related Questions

Missing Method Exception and Null Reference Exception 3 Answers

MissingMethodException with jslib calling c# functions 0 Answers

Cannot build to PC platform due to two errors. 1 Answer

Unity & Facebook MissingMethodException: Method not found: 'UnityEngine.Screen.get_showCursor'. 0 Answers

Cookie Cutter Script and 'MissingMethodException' 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