What does this error mean? ArgumentException: method arguments are incompatible

Having some trouble with this script.

I was testing and everything was fine until I finished adding the CreateTriggerObj() function i tried to run the project and now as soon as I click on any ui object this error is thrown. I mention CreateTriggerObj() because that was the last thing I was working on before this error appeared.

I did a quick google search and from what i have read this error is thrown when creating dynamic delegates but Im not creating any at runtime so im a little confused.

I am not sure what this error means. I tried to redesign the ui elements incase something was lost there but the error is still always thrown.

script is pasted below the error snippet.

ArgumentException: method arguments are incompatible
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) (at <fb001e01371b4adca20013e0ac763896>:0)
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) (at <fb001e01371b4adca20013e0ac763896>:0)
UnityEngine.Events.InvokableCall..ctor (System.Object target, System.Reflection.MethodInfo theFunction) (at <a9810827dce3444a8e5c4e9f3f5e0828>:0)
UnityEngine.Events.PersistentCall.GetRuntimeCall (UnityEngine.Events.UnityEventBase theEvent) (at <a9810827dce3444a8e5c4e9f3f5e0828>:0)
UnityEngine.Events.PersistentCallGroup.Initialize (UnityEngine.Events.InvokableCallList invokableList, UnityEngine.Events.UnityEventBase unityEventBase) (at <a9810827dce3444a8e5c4e9f3f5e0828>:0)
UnityEngine.Events.UnityEventBase.RebuildPersistentCallsIfNeeded () (at <a9810827dce3444a8e5c4e9f3f5e0828>:0)
UnityEngine.Events.UnityEventBase.PrepareInvoke () (at <a9810827dce3444a8e5c4e9f3f5e0828>:0)
UnityEngine.Events.UnityEvent`1[T0].Invoke (T0 arg0) (at <a9810827dce3444a8e5c4e9f3f5e0828>:0)
UnityEngine.UI.InputField.SendOnSubmit () (at C:/Program Files/Unity/Hub/Editor/2020.1.6f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/InputField.cs:2171)
UnityEngine.UI.InputField.DeactivateInputField () (at C:/Program Files/Unity/Hub/Editor/2020.1.6f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/InputField.cs:2985)
UnityEngine.UI.InputField.OnDeselect (UnityEngine.EventSystems.BaseEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2020.1.6f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/InputField.cs:3007)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IDeselectHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2020.1.6f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:113)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/Program Files/Unity/Hub/Editor/2020.1.6f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2020.1.6f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:376)
using System.Collections;
using System.Collections.Generic;
using UnityEngine.EventSystems;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System;

[Serializable]
public class TriggerItem {
  public int index;
  public string id;
  public string triggertext;
  public string channelnotice;
  public bool usemecolor;
}
public class TriggerCommandManager: MonoBehaviour {

  public string addTriggerText;
  public string addNoticeText;
  public int totaltriggers;
  public TriggerItem[] triggerEntries;
  public GameObject triggerPanelDisplay;

  public GameObject TriggerElement;

  public GameObject NewTriggerInput;
  public GameObject NewChannelNoticeInput;
  public GameObject NewMeColorToggle;
  public GameObject EditTriggerPanel;

  public GameObject TriggerDialog_Panel;

  public static GameObject trigbtn;

  public GameObject statusdisplay;
  public GameObject EditTriggerTextDisplay;
  public GameObject EditChannelNoticeDisplay;

  // Start is called before the first frame update
  void Start() {

}

  // Update is called once per frame
  public void SetEntries() {
    totaltriggers = 100;
    triggerEntries = new TriggerItem[totaltriggers];
  }

  public void AddToTriggerList() {

    InputField triggerfield = NewTriggerInput.GetComponent < InputField > ();
    InputField noticefield = NewChannelNoticeInput.GetComponent < InputField > ();
    Toggle colortoggle = NewMeColorToggle.GetComponent < Toggle > ();

    addTriggerText = triggerfield.text;
    addNoticeText = noticefield.text;

    if (addTriggerText != "") {
      if (addTriggerText != " ") {
        //CreateVote_Panel.SetActive(true);
        //TriggerDialog_Panel.SetActive(true);
        if (TriggerDialog_Panel.activeSelf == true) {
          int onum = 0;
          if (triggerEntries.Length > 0) {

            foreach(TriggerItem tItem in triggerEntries) {
              if (tItem != null) {

                if (tItem.index == 0) {
                  if (tItem.index < 0) {
                    break;
                  }
                  break;

                }
              }
              onum = onum + 1;
            }
            if (onum < totaltriggers) {
              triggerEntries[onum] = new TriggerItem();
              triggerEntries[onum].index = onum + 1;

              triggerEntries[onum].id = UnityEngine.Random.Range(22222222, 88888888).ToString();

              triggerfield = NewTriggerInput.GetComponent < InputField > ();
              noticefield = NewChannelNoticeInput.GetComponent < InputField > ();
              colortoggle = NewMeColorToggle.GetComponent < Toggle > ();

              addTriggerText = triggerfield.text;
              addNoticeText = noticefield.text;

              triggerEntries[onum].triggertext = addTriggerText;
              triggerEntries[onum].channelnotice = addNoticeText;
              triggerEntries[onum].usemecolor = colortoggle.isOn;

              updateTriggerList();
            }
          } else {
            updatestatusdislpay("Maximum amount of triggers used edit or remove one.");
          }
        }
      }
      else {
        updatestatusdislpay("Trigger field cannot be blank fill it and try again.");
      }
    }
    else {
      updatestatusdislpay("Trigger field cannot be blank fill it and try again.");
    }
  }
  public void CreateTriggerObj(int optindex, string optid, string triggertext, string cnotice, bool usecolor) {

    Vector3 newpos = new Vector3(0, 0, 0);
    GameObject newTriggerObject = (GameObject) Instantiate(TriggerElement.gameObject, newpos, Quaternion.identity);

    TriggerConfigSettings TSettings = newTriggerObject.GetComponent < TriggerConfigSettings > ();

    TSettings.index = optindex;
    TSettings.id = optid;
    TSettings.triggertext = triggertext;
    TSettings.channelnotice = cnotice;
    TSettings.usemecolor = usecolor;
    TSettings.updateThisTrigger();

    newTriggerObject.name = "TriggerItem-" + optid;
    newTriggerObject.gameObject.transform.SetParent(triggerPanelDisplay.transform);
    newTriggerObject.transform.GetChild(2).transform.GetChild(0).GetComponent < Button > ().onClick.AddListener(delegate {
      GetEventClickedTriggerButton();
    });
    newTriggerObject.transform.GetChild(2).transform.GetChild(0).GetComponent < Button > ().onClick.AddListener(delegate {
      EditTriggerCommand();
    });
    //Debug.Log(newOptObject.name);

  }
  public void HideEditTriggerOnClick() {

    if (EditTriggerPanel.activeSelf == true) {
      EditTriggerPanel.SetActive(false);
    }
  }
  public void EditTriggerCommand() {
    if (EditTriggerPanel.activeSelf != true) {
      if (trigbtn != null) {
        TriggerConfigSettings TCS = trigbtn.gameObject.transform.parent.parent.GetComponent < TriggerConfigSettings > ();

        if (TCS.id != "0") {
          //Debug.Log(OCS.optiontext);
          EditTriggerTextDisplay.GetComponent < InputField > ().text = TCS.triggertext;
          EditChannelNoticeDisplay.GetComponent < InputField > ().text = TCS.channelnotice;

          EditTriggerPanel.SetActive(true);
        }
      }
    }

  }
  public static GameObject GetEventClickedTriggerButton() {
    EventSystem currentEvent = EventSystem.current;

    if (currentEvent.currentSelectedGameObject.ToString().Contains("EditTriggerOptBtn")) {
      trigbtn = currentEvent.currentSelectedGameObject.gameObject;
      //EditVoteOption();
      //Debug.Log(trigbtn);
    }

    return currentEvent.currentSelectedGameObject;
  }
  public void updateTriggerList() {

    foreach(Transform t in triggerPanelDisplay.transform) {
      Destroy(t.gameObject);
    }

    int foundtriggers = 0;

    foreach(TriggerItem titem in triggerEntries) {
      //if (oitem.optiontext != null) {
      if (titem.triggertext != "") {
        if (titem.triggertext != " ") {
          if (titem.triggertext != null) {

            CreateTriggerObj(titem.index, titem.id, titem.triggertext, titem.channelnotice, titem.usemecolor);
            foundtriggers = foundtriggers + 1;

          }
        }
      }
      //}

    }

    //ChannelVoteHandler.GetComponent<LiveResultsManager>().GetLiveOptions(foundoptions);
    //LiveResultsManager LRManager = ChannelVoteHandler.GetComponent < LiveResultsManager > ();
    //LRManager.updateOptionsList();
  }
  public void updatestatusdislpay(string updatestring) {
    statusdisplay.GetComponent < Text > ().text = updatestring;
  }
}

It looks like its coming from an InputField UnityEvent. Did you assign a callback in the editor and then later change the signature of the callback method? Take a look in the inspector at your input fields and see what methods they are calling. They should either take no arguments or a single string.

1 Like

That is very possible I thought I copied only the scripts but I may have copied a few gameobjects that are retaining some old information. I will take a look. Thanks for the input.

That was it. I must have clicked the + button for OnEndEdit for a inputfield. it seams to be working fine now. thanks again.

1 Like

Maybe you can help me with this also. So I cant seam to get AddToTriggerList() to work The only way it works is if I select the gameobect that contains the script TriggerCommandManager manually in the hierarchy. As soon as i click it in the hierarchy the try to add a new trigger word it works. I tried to use TriggerDialog_Panel.SetActive(true); on line 63 to ensure the script is active and enabled but it does not seams to work.

Sorry, I don’t know. Try stepping through AddToTriggerList in the debugger.