- Home /
UI object gets bigger when attached on Content in ScrollView
I made some prefabs consist of UI objects. When I put those prefabs on the Content in ScrollView, their scales get bigger from (1,1,1) to (2,2,2). I have no clues why this happens. Here's my codes.
...
public RectTransform content, prefab_obj;
...
...
void CreateData() {
...
RectTransform prefab = Instantiate(prefab_obj);
prefab.SetParent(content);
...
It's working well except the scale. I wonder what causes this problem. Can anybody help me? Thanks in advance for any help.
Try adding a LayoutElement component to the prefab. It should allow you to specify whether or not you want the prefab to expand to fit the size of the ScrollView or to be a specific size.
It doesn't work with it. Thanks anyway for your time :)
$$anonymous$$ost likely your canvas or scrollview is scaled to (.5,.5,.5), so when you drag the prefab under it, to keep the same absolute scale, it has to double the scale relative to the parent.
You are right!!!! So I put 'prefab.localScale = new Vector3(1.0f, 1.0f, 1.0f);' and it worked. Thank you so much! But I wonder if this is a right solution.