Search Unity

Question Method arguments are incompatible

Discussion in 'Scripting' started by denissuu, Sep 18, 2020.

  1. denissuu

    denissuu

    Joined:
    Nov 6, 2019
    Posts:
    162
    Hi there everyone!I was working on my menu, and I wanted to copy the menu from the in-game pause to the main menu scene and just modify it slightly.I remade all the references back in the inspector, made a separate script for modifying sensitivity and quality that did the same thing as the one in the in-game pause menu.And as soon as I wanted to test it out, Unity throws me a really weird error that broke both of my menus. Every time I try to press a button to enter the menus, or pressing buttons inside the menu, I'm getting errors like the following :


    Code (CSharp):
    1. ArgumentException: method arguments are incompatible
    2. System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) (at <fb001e01371b4adca20013e0ac763896>:0)
    3. System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) (at <fb001e01371b4adca20013e0ac763896>:0)
    4. UnityEngine.Events.InvokableCall..ctor (System.Object target, System.Reflection.MethodInfo theFunction) (at <2e6610ed29844f85a37924f81509fe5d>:0)
    5. UnityEngine.Events.PersistentCall.GetRuntimeCall (UnityEngine.Events.UnityEventBase theEvent) (at <2e6610ed29844f85a37924f81509fe5d>:0)
    6. UnityEngine.Events.PersistentCallGroup.Initialize (UnityEngine.Events.InvokableCallList invokableList, UnityEngine.Events.UnityEventBase unityEventBase) (at <2e6610ed29844f85a37924f81509fe5d>:0)
    7. UnityEngine.Events.UnityEventBase.RebuildPersistentCallsIfNeeded () (at <2e6610ed29844f85a37924f81509fe5d>:0)
    8. UnityEngine.Events.UnityEventBase.PrepareInvoke () (at <2e6610ed29844f85a37924f81509fe5d>:0)
    9. UnityEngine.Events.UnityEvent.Invoke () (at <2e6610ed29844f85a37924f81509fe5d>:0)
    10. UnityEngine.UI.Button.Press () (at E:/Programe/2020.1.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:68)
    11. UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at E:/Programe/2020.1.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:110)
    12. UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at E:/Programe/2020.1.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)
    13. UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at E:/Programe/2020.1.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
    14. UnityEngine.EventSystems.EventSystem:Update() (at E:/Programe/2020.1.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:376)

    Does Unity really not like duplicating things from one scene to another and then just separate their scripts?

    I'm afraid that I might've lost all of the work that's been gone into this, as I didn't use collaborate until now. :/

    Does anybody have any idea why does this happen?It completely broke my menus and I honestly can't read and understand anything out of this huge error.

    Thanks for the help!

    I'm not really sure where this issue should be, so I just posted it in this category.
     
    uncoded_coder likes this.
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    The error is saying that the function you're calling on button click doesn't have the right number of arguments. Check the onClick assignment in the inspector vs your function declaration and make sure the number of arguments is correct.
     
  3. denissuu

    denissuu

    Joined:
    Nov 6, 2019
    Posts:
    162

    You were right, I had some empty references at OnClick for some reason.Thank you so much! :)
     
    Bunny83, ErkanAkin, BuildByte and 6 others like this.
  4. AmISquidward

    AmISquidward

    Joined:
    May 20, 2021
    Posts:
    18
    and how do i do that?
     
  5. alex_roboto

    alex_roboto

    Joined:
    Nov 11, 2019
    Posts:
    26
    You will also see "ArgumentException: method arguments are incompatible" if one of your handlers of the UnityEvent has GameObject:None. This usually happens if you deleted the GameObject but forgot to remove it as a listener to the UnityEvent but it could also happen just by pressing the + button in the UI and forgetting to hooking up a GameObject or manually setting the GameObject to None.
     
    Bunny83, bantus, Danilogb18 and 3 others like this.
  6. nilesh410451

    nilesh410451

    Joined:
    Aug 22, 2012
    Posts:
    4
    Download LTS of unity version. The issue is resolved in it
     
  7. Zachferio

    Zachferio

    Joined:
    Sep 3, 2020
    Posts:
    1
    Thanks for engaging in this thread. I was giving myself a headache trying to figure out what that error was and it turns out that I had a button in a prefab that I forgot was even a button and it had an empty event. :)
     
    mohanyadav likes this.
  8. mohanyadav

    mohanyadav

    Joined:
    Jan 4, 2016
    Posts:
    2
    Had a similar issue when I stumbled upon this thread. Turns out the button prefab had an empty event. Removed the empty event in the prefab and saved it. Now works perfectly