UI Prefab lose its orignal Rect Transform values

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Matcha
Posts: 10
Joined: Fri Dec 31, 2021 1:12 am

UI Prefab lose its orignal Rect Transform values

Post 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 1599 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 1599 times
Is there a way to solve this problem? Thanks!
User avatar
Tony Li
Posts: 22140
Joined: Thu Jul 18, 2013 1:27 pm

Re: UI Prefab lose its orignal Rect Transform values

Post 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?
Matcha
Posts: 10
Joined: Fri Dec 31, 2021 1:12 am

Re: UI Prefab lose its orignal Rect Transform values

Post 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.
Matcha
Posts: 10
Joined: Fri Dec 31, 2021 1:12 am

Re: UI Prefab lose its orignal Rect Transform values

Post 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.
User avatar
Tony Li
Posts: 22140
Joined: Thu Jul 18, 2013 1:27 pm

Re: UI Prefab lose its orignal Rect Transform values

Post 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.
User avatar
Tony Li
Posts: 22140
Joined: Thu Jul 18, 2013 1:27 pm

Re: UI Prefab lose its orignal Rect Transform values

Post 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
Matcha
Posts: 10
Joined: Fri Dec 31, 2021 1:12 am

Re: UI Prefab lose its orignal Rect Transform values

Post by Matcha »

That's a great suggestion! Thanks! :D
Post Reply