Dialog Manager chooses wrong parent canvas on initialization

+1 vote
asked Oct 30, 2016 in Critical bug by hivemind (140 points)
Hi

When the DialogManager is first instantiated, it finds a random parent canvas using FindObjectOfType<Canvas>. Unfortunately for us, we have some canvases used as 3D UIs which have been scaled. Randomly one of these gets chosen as the DialogManager's parent, and the dialogs end up massively out of scale.

I'm sure you'll know what a good solution is for this. My suggestion would be to search for a Material UI Scaler and use the canvas/transform associated with it.

Cheers,

Darren
commented Jan 5, 2017 by admin (31,720 points)

Hi Darren,

I'll shortly be reworking DialogManager (as well as other 'manager' components) to properly support multiple Canvasses.

In the meantime, you can work around this by calling the respective CreateDialog method to the ShowDialog one you're using.

For example, if you are currently calling:

DialogManager.ShowAlert("body text", "title text", null);

You could instead call:

DialogAlert dialog = DialogManager.CreateAlert();
dialog.Initialize("body text", () => Debug.Log("OK Button clicked"), "OK", "title text", null, null, "DISMISS");
dialog.rectTransform.SetParentAndScale(canvas.transform, Vector3.one);
dialog.rectTransform.localEulerAngles = Vector3.zero;
dialog.Show();

(where 'canvas' is the Canvas you want the dialog to show under)

Let me know if that helps!

~ Declan.

1 Answer

0 votes
answered Oct 30, 2016 by admin (31,720 points)
Hi Darren,

To specify an explicit canvas to use, you can create a DialogManager at design time and set the 'parent canvas' value in the inspector to the desired canvas :)

~ Declan.
commented Dec 12, 2016 by Abhishek
hi Declan,

i followed the same , set 'parent canvas' at design time, still it has the same issue, it gets the wrong parent canvas, in some cases i have also noticed that when i am using multiple dialog managers for different screens, the first one i open gets the correct canvas, and after that all the dialog managers get the wrong parent canvas.

Thanks.
Abhishek
commented Jan 5, 2017 by admin (31,720 points)

Hi Abhishek,

I'll shortly be reworking DialogManager (as well as other 'manager' components) to properly support multiple Canvasses.

In the meantime, you can work around this by calling the respective CreateDialog method to the ShowDialog one you're using.

For example, if you are currently calling:

DialogManager.ShowAlert("body text", "title text", null);

You could instead call:

DialogAlert dialog = DialogManager.CreateAlert();
dialog.Initialize("body text", () => Debug.Log("OK Button clicked"), "OK", "title text", null, null, "DISMISS");
dialog.rectTransform.SetParentAndScale(canvas.transform, Vector3.one);
dialog.rectTransform.localEulerAngles = Vector3.zero;
dialog.Show();

(where 'canvas' is the Canvas you want the dialog to show under)

Let me know if that helps!

~ Declan.

Welcome to MaterialUI support! Ask us anything :)
...