Why does my Toast have inconsistent positions (editor bug)

0 votes
asked Oct 26, 2016 in Editor by Ian Grant
Hi, Loving the asset.

I posted the following to the Unity Forum for Material UI:

Hi, I worked out a minimal example and the behaviour is present:

Hi, Two things: I'm creating a 'toast' when an object is enabled. The first toast appears central. The next toast is offset and slightly off-screen. If I repeatedly (de)activate the objects that trigger the toast, eventually a future toast is central again.

I think: if I activate a toast when the first is still displayed, the next toast is central.

If I wait for the toast to disappear and enable the next toast - it is offset on the -X

Is there something I can manually destroy to ensure the toasts are always central?

[2] The second thing: can I have a multiline toast? What would be the line-break character?

...

Then followed up after some investigation and making a smaller example (my scene originally had a tab set on a nav element and I thought the canvas settings might be screwy.

So:

In Game mode: Disable and re-enable an object in the editor then using a switch that is set to toggle the object) with the following delays:

[1] Wait for the toast to finish

[2] Interupt the toast.

Note the positions:

When enabled/disabled In the Editor:

[1] Central

[2] Off on the -X

Using the switch, all behaved as expected.

So this is not a world changing bug as it only happens using the editor at game time - but it appeared during testing before I'd built the UI to enable / disable the objects and I scratched my head and around for a solution for a while...

Cheers Ian

1 Answer

0 votes
answered Nov 21, 2016 by admin (31,720 points)
 
Best answer

Hi Ian!

(I've just answered on the forum, but I post it here too)

I've searched why this issue happens, and you're right, it's only in the Editor. You won't have this issue in builds.
The reason is that, to display toasts at the correct position, we use Screen.width and Screen.height, which returns the current window dimensions.
And here's the issue, it's the current window dimensions, not the Game View dimensions.
This mean that if you're "activating" things from the Game View (by using switches for example), it will work fine, because the current window is the GameView. But if you activate/deactivate a GameObject from the Inspector, or Hierarchy or anywhere else... well... Screen.width and Screen.height will return the dimensions of the Inspector (or Hierarchy). So that's the issue :)
And in builds you don't have this issue, because the current window is always the Game window!

I've submitted a bug report to Unity for that. We'll see if they fix that or not.

If you don't want this issue, just make sure you trigger everything from the GameView :)
Have a great day and thanks for reporting the issue!

~ Yohan

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