Search Unity

Multiple Constraints on GridLayoutGroup Component

Discussion in 'Scripting' started by jlc1830, May 29, 2017.

  1. jlc1830

    jlc1830

    Joined:
    May 28, 2017
    Posts:
    4
    I'm working with the UI and one of my panels use the GridLayoutGroup component. Is it possible, through scripting, to write two constraint values for the LayoutGroup?
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Like, do you mean fixed column + fixed row? If that's what you were asking, that's impossible, afaik. It's one or the other.
    But when you have one, you can usually set it up so the other does what you want.. I think.. :)
    If by chance you meant, could you have a script that changes between the two values, then the answer is yes.. :)
    They just can't be on at the same time.
     
    jlc1830 likes this.
  3. jlc1830

    jlc1830

    Joined:
    May 28, 2017
    Posts:
    4
    Yes that is exactly what I was asking. In fact, before I posed the question I had already written a script that set constraints separately one after the other and my suspicions were confirmed when I ran the game and it just switched to the latest defined constraint from the script. Not that I require multiple constraint rules anymore (I've decided it's unnecessary for my requirements), but how do you mean I can "set it up so the other does what I want"?
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Well, all I meant by that was.. say you lock the grid to width of 5.
    Then are in charge of how many you add. if you add 20, you've now locked at 4 'tall'. that's all I meant. :) I mean, it's not locked by the game, so much as by .. just common sense. the grid is just helping you lay it out.
     
    jlc1830 likes this.
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You can do this another way with nested vertical and horizontal layout elements.
     
    jlc1830 likes this.
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    True :) All depends on what they're up to.
     
  7. jlc1830

    jlc1830

    Joined:
    May 28, 2017
    Posts:
    4
    Okay I gotchu. Yeah I realized that and that's what I meant by "no longer necessary". Thanks a lot for the input!
     
  8. jlc1830

    jlc1830

    Joined:
    May 28, 2017
    Posts:
    4
    Okay, awesome tip, thanks!
     
  9. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You're welcome. Have fun :)