- Home /
 
               Question by 
               Beks_Omega · Jan 27, 2018 at 12:10 AM · 
                uipositionlayoutanchor  
              
 
              How to Force a Layout Group to Rebuild
I need the updated anchored positions of a Horizontal Layout Group's children in the Start function for a component I am working on. The problem is that in the Start function all of the children return an anchored position of (0,0) because they haven't been built yet.
I can make them build like so:
 public HorizontalLayoutGroup horizLayoutGroup;
 public RectTransform exampleChild;
 
 private void Start()
 {
     horizLayoutGroup.CalculateLayoutInputHorizontal();
     horizLayoutGroup.CalculateLayoutInputVertical();
     horizLayoutGroup.SetLayoutHorizontal();
     horizLayoutGroup.SetLayoutVertical();
 
     Debug.Log(exampleChild.anchoredPosition);
 }
But I was wondering if there was a better way to do this.
I have also tried:
 public RectTransform horizRectTransform;
 public RectTransform exampleChild;
 
 private void Start()
 {
     LayoutRebuilder.ForceRebuildLayoutImmediate(horizRectTransform);
     Debug.Log(exampleChild.anchoredPosition);
 }
But it doesn't actually seem to force the layout to rebuild, oddly enough. So if anyone can give me confirmation that this is what you're supposed to do, or a better way of doing it I would super appreciate it! Thank you!
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                