- Home /
Scroll Rect is "weighted" and doesn't let players scroll up very far
Hi folks,
I'm working on a texting simulator game, so almost everything is UI based (blech, I know). Something that's really stumped me is the Scroll Rect component not working correctly. If I try to scroll up on the texting screen, I can do that for a moment, but then the content gets dragged back down again, almost like it's bottom-heavy. This sucks because it means that if players forget what a certain character said during a previous conversation, or if the texts are coming in too fast for them to read, they can't scroll back :/
In my hierarchy, I have a Scroll Rect object. Nested under that is a "content holder" that contains, as childed gameobjects, an object for each conversation. The content holder is specified as the Scroll Rect's content. I'm pretty sure something is off on either my anchor presets or pivots, or I have a box checked on a layout group that shouldn't be. But I have tried SO many configurations and none of them fix the problem.
Here are some screenshots of my hierarchy/inspector settings, and here's a quick video of the issue in action.
Answer by thelastelfl · Feb 09, 2021 at 03:24 PM
you should add component "Vertical Group Layout" and "Context Size Fitter" on Content, and set value "Horizontal Fit" and "Vertical Fit" as "Min size".,You should add component "Context Size Fitter" on Content, and set both value "min size"
This worked, thanks! Though I think your answer repeats some words - I didn't have to change anything on the vertical group layout, just left it as-is.
Answer by epb267 · Feb 08, 2021 at 04:16 PM
one more screenshot (I can only include 2 per posts) as well as the only code that messes with these objects.
public void WriteText(string text, string characterName, bool isRosa){
if(text == ""){
return;
}
Character character = Services.CharacterManager.characters[characterName];
Transform parent = character.transform;
GameObject textObj;
if(isRosa){
textObj = GameObject.Instantiate(rosaPrefab,parent);
}else{
textObj = GameObject.Instantiate(conversantPrefab,parent);
Services.CharacterManager.characters[Services.InkManager.currentConversant].textingInProgressIcon.transform.SetAsLastSibling();
}
textObj.transform.localPosition = new Vector2(0,character.height);
TextMeshProUGUI textDisplay = textObj.GetComponentInChildren<TextMeshProUGUI>();
textDisplay.text = text;
character.texts.Add(text);
character.height -= 0;
textDisplay.DOFade(1f, 1f);
textObj.GetComponentInChildren<Image>().DOFade(1f, 1f);
textObj.transform.DOShakeScale(.5f, .03f, 10, 0f, true);
}