Page 1 of 1

UI Prefab lose its orignal Rect Transform values

Posted: Sun Jun 05, 2022 10:49 pm
by Matcha
I tried to create a UI prefab that will be responsive to its parent canvas setting, this is its original Rect Transform values
Image [3].png
Image [3].png (13.95 KiB) Viewed 1598 times
It works fine if I directly drag and drop this prefab under the canvas under dialogue manager, but when I use it in the Dialogue UI under the display settings and run the game, the value is changed to some really weird numbers
Image [4].png
Image [4].png (13.88 KiB) Viewed 1598 times
Is there a way to solve this problem? Thanks!

Re: UI Prefab lose its orignal Rect Transform values

Posted: Mon Jun 06, 2022 7:52 am
by Tony Li
Hi,

The Dialogue Manager has a Default Canvas field that, by default, points to a canvas with a Canvas Scaler that scales to a reference resolution of 960x600. You can, of course, change the Canvas Scaler or point the Default Canvas field to a different canvas if you want. I don't think the Canvas Scaler is the entire issue, since it would presumably limit your UI to 960x600, but I mention it in case it has some effect on what's going on.

Does your canvas have any layout components such as a Vertical Layout Group or Content Size Fitter that might change your dialogue UI's layout when it becomes a child of that layout component?

Re: UI Prefab lose its orignal Rect Transform values

Posted: Mon Jun 06, 2022 2:13 pm
by Matcha
Hi Tony,

I change the default canvas field's canvas scaler to 1080*1920 (since I'm making a mobile game) and I also change the screen match mode to "expand". Not sure if that's the reason?

I do have a vertical layout group and content size fitter for some of the elements like subtitle background and nametag background... If I directly drag my UI prefab under the dialogue manager's default canvas, then everything works perfectly fine.

I've found a temporary way to solve this by selecting "add instance" and manually changing its Rect Transform, but I do hope I can find a way to directly use the prefab since I want to update my settings and layout across the scenes by updating the prefab.

Re: UI Prefab lose its orignal Rect Transform values

Posted: Mon Jun 06, 2022 2:13 pm
by Matcha
Hi Tony,

I change the default canvas field's canvas scaler to 1080*1920 (since I'm making a mobile game) and I also change the screen match mode to "expand". Not sure if that's the reason?

I do have a vertical layout group and content size fitter for some of the elements like subtitle background and nametag background... If I directly drag my UI prefab under the dialogue manager's default canvas, then everything works perfectly fine.

I've found a temporary way to solve this by selecting "add instance" and manually changing its Rect Transform, but I do hope I can find a way to directly use the prefab since I want to update my settings and layout across the scenes by updating the prefab.

Re: UI Prefab lose its orignal Rect Transform values

Posted: Mon Jun 06, 2022 2:26 pm
by Tony Li
In either case, I recommend making your Dialogue Manager into a prefab or prefab variant. Then you can use the same Dialogue Manager in all scenes. You can add an instance of your dialogue UI to this prefab if you can't figure out why the RectTransform values are changing when the dialogue UI prefab is instantiated at runtime.

Re: UI Prefab lose its orignal Rect Transform values

Posted: Mon Jun 06, 2022 2:40 pm
by Tony Li
You could also try this patch containing an update that's in the upcoming version 2.2.28. It has some improvements to instantiating dialogue UI prefabs.

DS_UIPrefabPatch_2022-06-06.unitypackage

Re: UI Prefab lose its orignal Rect Transform values

Posted: Mon Jun 06, 2022 2:48 pm
by Matcha
That's a great suggestion! Thanks! :D