I had trouble assigning onClick listeners within a loop, and found that separating the assignment of the listener fixed my issue. I’m not familiar with ‘DialogTopicVoid’ and assigning methods this way, but what if you did something like:
public void CreateDialogButton(string ButtonText, int id, DialogTopicVoid Dialog) {
CreateButton = Instantiate(DialogButton);
CreateButton.transform.parent = DialogWindowPanel.transform;
PosY = (id == 0) ? 85 : PosY - 30;
CreateButton.GetComponent<RectTransform>().localPosition = new Vector3( PosX, PosY, PosZ );
CreateButton.GetComponent<RectTransform>().sizeDelta = new Vector2( SizeX, SizeY );
CreateButton.GetComponentInChildren<Text>().text = ButtonText;
CreateButton.name = ButtonText;
AssignDialog(CreateButton.GetComponent<Button>(), Dialog());
}
public AssignDialog(Button btn, DialogTopicVoid dialog) {
btn.onClick.AddListener(() => dialog);
}
Doesn’t works
DialogTopicVoid is a delegate void because the function is transmitted from another script but if I try use function from this scripts it’s the same.
So, I’ve tried all the methods suggested by you guys, and all of them works. So, I think your problem lies elsewhere. Is your scene correctly set up? Is there an EventSystem in your scene? If there isn’t there won’t be any click events generated.