Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Scroll View with Panels in Content

Discussion in 'UGUI & TextMesh Pro' started by diggyk, Aug 28, 2020.

  1. diggyk

    diggyk

    Joined:
    Aug 16, 2014
    Posts:
    24
    I'm tearing my hair out!

    I've got a scroll view. The content is set to control child size width and use child scale for height (vertical layout group) and a content size fitter. In it, I want to add some prefabs which are a UI panel with with a horizontal layout group and two children, which are text. When I drag and drop the prefab as a child of the scroll view's content, it looks just fine. But when I do this dynamically via script by instantiating the prefab and setting the parent, it is just completely wrong (in various ways, depending on what I'm testing). So, what's the deal? I can find super simple tutorials about adding text to content and I can do that, too, without issue. But does any one have luck with prefabs?

    What I want to do is the prefab expand in width to match the width of the scrollview and have the text move along with the new width.
     
  2. diggyk

    diggyk

    Joined:
    Aug 16, 2014
    Posts:
    24
    Okay, I think i solved this issue. When adding the prefabs to the content, I was using `transform.SetParent(blah)` instead of `transform.SetParent[blah, false);`