- Home /
Unity Button onclick triggers ArgumentException
Hey,
when I try to create a Unity Button from a prefab, and then try to add an onClick listener to it, triggering this listener by clicking the button gives me an ArgumentException. Here is the Code I used to create the Button:
GameObject ButtonToBeBuilt = Instantiate(UiButton, UiCanvas.transform);
ButtonToBeBuilt.GetComponent<Button>().onClick.AddListener(FunctionToBeExecuted);
Something I also tried was adding my function to a UnityAction, and passing the UnityAction
to the AddListener function, however, it did not change the result. Furthermore I tried putting delegate{FunctionToBeExecuted();}
as a parameter for the AddListener function and it did not help either.
Do you guys have any idea on how to fix it? Thanks in advance.,
Comment