instantiatedButtons return 0

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

instantiatedButtons return 0

Post by alfonso »

Hi i have a little problem with this code and the dialogue.responseMenu.instantiatedButtons variable.

here the code:

Code: Select all

public override void ShowResponses (Subtitle subtitle, Response[] responses, float timeout) {
			base.ShowResponses(subtitle, responses, timeout);
			SetButtonsNav();
			if (autoFocus) dialogue.responseMenu.AutoFocus(); 
		}
		void SetButtonsNav()
		{
			List<GameObject> buttons = dialogue.responseMenu.instantiatedButtons;
			Debug.Log (buttons.Count);
			int totals = buttons.Count;
			for(int i = 0; i < totals; i++)
			{
				Navigation current = buttons[i].GetComponent<Button>().navigation;
				current.selectOnUp = (i == 0)? buttons[totals-1].GetComponent<Button>(): buttons[i-1].GetComponent<Button>();
				current.selectOnDown = (i == totals)? buttons[0].GetComponent<Button>(): buttons[i+1].GetComponent<Button>();
			}
		}
NOTE: the buttons are in explicit mode
the main idea is setup the nav of the response buttons like doc recomend becouse the automatic one is little crazy and in the game when i talk with a NPC who has various responses show me the corrects number of buttons but the dialogue.responseMenu.instantiatedButtons give a value of 0 buttons and dont enter in the loop :(

and other rare thing is the showResponse is called twice (the same number of buttons of the npc im using to) this is normal?

im using the new unity ui and the canvas is on world space

Thank you so much for the help
User avatar
Tony Li
Posts: 22100
Joined: Thu Jul 18, 2013 1:27 pm

Re: instantiatedButtons return 0

Post by Tony Li »

Hi,

When using explicit buttons (defined in Dialogue > Response Menu > Buttons), the dialogue UI will not instantiate any other buttons, so instantiatedButtons will be empty. You can loop through dialogue.responseMenu.buttons instead. Unused buttons will be disabled.

ShowResponses() shouldn't be called twice. Please feel free to email an example project to tony (at) pixelcrushers.com. I'll be happy to take a look.

Tony
Post Reply