Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Getting a "MissingMethodException" for a method I'm not currently using

Discussion in 'Scripting' started by mortoray, Aug 6, 2023.

  1. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    89
    I'm getting the error `MissingMethodException: Method 'EREngine.ContextHelp.OnPoint' not found.` I know what method it means, and it's confusing for two reasons:

    - the method exists
    - the message persists even if I stop using the method

    In my component I have this code for the mentioned function:

    Code (CSharp):
    1.     Vector2 curPosition;
    2.     void OnPoint(InputAction.CallbackContext context) {
    3.         curPosition = context.ReadValue<Vector2>();
    4.     }
    5.  
    I'm using this code to track the current pointer position, so in the `Start` method I have:

    Code (CSharp):
    1.  
    2.        var actionPoint = map.FindAction("Point", true);
    3.        actionPoint.performed += OnPoint;
    4.  
    I'm confused as to how this is generating the `MissingMethodException`. I was working on this yesterday and didn't notice any problems, but when I opened the project this morning the error starting appearing

    If I remove the code in the `Start` function, the one that adds a listener using `OnPoint`, the error message persists! If I remove the function it goes away, but the moment I add it back it comes back.

    As another test, I change the name from `OnPoint` to `OnPointy` and the error goes away, at least for now.

    Does anybody have any ideas what could be causing this?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    MissingMethodException may be thrown if the implemented method, as in your case, is private. It's possible that it is required to be declared public or at least internal. It may also expect a method with a different signature (parameters), although this one looks alright to me.


    I'm alway cautious when it comes to "finding" some object reference by string. If there is any other method for Input System and your current setup, and I believe there is, I would opt to use a different strategy than finding an action by string. Simply because this will break if you ever rename "Point" to something else in the Input Map editor.

    I tend to prefer using the auto-generated class which should already provide you with these callback methods (eg OnPoint), so there's no need to "find" any of the actions. The samples in the package have a demo with all four variants you can use to hook into the input system, maybe check those out.

    Then I wonder if any of these methods is static, particularly if you have "Disabled Domain Reload" enabled in Project Settings => Editor. With disabled domain reload static variables are no longer reset to null / 0 which is particularly nasty for events as they will continue to fire.
     
  3. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    89
    Nothing is using the `OnPoint` method though when I get this error. I commented out my action code and the error is still happening. It's something particular to the name `OnPoint` it appears -- since renaming also makes it go away. That's the primary question, what is trying to reference my OnPoint method?

    None of the methods involved are static. It's a normal instantiated component attached to a GameObject.

    Yeah, I'll bind as a property later, or grab it directly from the InputSystem to be consistent. I'm just testing out some code right now. I do need the actual InputAction though, not just a handler. I'm disabling the action and creating a clone in order to create an interactive help system.
     
  4. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    The compiler reads all code, even though it doesn't technically use it yet. So if you don't have a "fall back" method within it, or a chance for it to be "null" and not give an error, it will throw an error.

    Then if it's just the function name, that seems to be giving the error, the compiler is seeing 2 of them, for some reason. If this is the case just rename that function.
     
  5. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,750
    If you don't get a compilation error but only a run time one, it's possible something is trying to find that method by name via reflection. It could be an UnityEvent or animation event. Those are notorious for creating hard to find references.
     
    spiney199 likes this.
  6. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    89
    I have no found anything referencing this `OnPoint`, but as @wideeyenow_unity suggest, I changed the name of the function and the problem goes away. It's something particular about the name `OnPoint` for some reason.
     
  7. sheffieldlad

    sheffieldlad

    Joined:
    Oct 9, 2013
    Posts:
    154
    If you're using VS as your IDE it should tell you just above the method how many references there are to that method.
    Click that to navigate through them all.
     
  8. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,750
    You can try using your IDE or a text editor like Notepad++ to search for OnPoint in all .unity, .prefab and .asset files in your asset folder. This is a last resort way to find "magic string" references to methods.
     
  9. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    89
    I did a search for `OnPoint` throught all files and this symbol doesn't occur anywhere (functions like `OnPointerClick` do, but never the plain `OnPoint` string.)