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

UI Button affects all parenting buttons as well

Discussion in 'UGUI & TextMesh Pro' started by DannyHellfish, Dec 24, 2014.

  1. DannyHellfish

    DannyHellfish

    Joined:
    Jan 20, 2014
    Posts:
    29
    Hey there,

    I wonder if I'm the only one with the following problem:

    As far as I can tell if you use animated buttons the animations always affect all parenting objects when they also have a button component, which is very unfortunate as you need to parent the game objects if you want to anchor them. (Which you need to do when buttons change their size according to the localized string). This happens with Color Tint as well as with custom button animations per animator.

    Is their a way to either anchor buttons to each other without parenting them or to change the buttons so they do not affect the parent objects?

    Thanks for your help,

    Hellfish
     
  2. DannyHellfish

    DannyHellfish

    Joined:
    Jan 20, 2014
    Posts:
    29
    Okay, I did some more digging and found out that it has actually nothing to do with the button component. The problem seems to be that the clickable area of UI elements is not only limited to the mesh of the UI but it includes all children as well.

    Is their a way to deactivate that as it de facto means that you cannot anchor buttons to each other as the parenting button will always include the clickable areas of all children.
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    A canvas group may help here. But I think it's actually a design issue.

    In general you don't need to have GameObjects as children of buttons. You can make them siblings and avoid all of this. If needed you can use an empty GameObject for grouping and sizing.
     
  4. DannyHellfish

    DannyHellfish

    Joined:
    Jan 20, 2014
    Posts:
    29
    Thanks for the answer. I would be interested how you would solve the following situation or design it differently.

    I have three buttons in a horizontal row which only consists of labels. The size of the labels can change depending on the localization. But I always want to have the same padding between them.

    I thought the correct way to do this ( and which works except the clickable area problem) is to anchor these buttons to each other and use a content fitter script so the size of the buttons match the string inside. But in order to anchor them to each other you need (?) to children them - at least with the new UI. (I had the same construction working with NGUI by the way) Putting empty gameobjects between them doesn't change the clickable area problem.
     
    Last edited: Dec 28, 2014
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Have you tried a horizontal layout + layout element?
     
    DannyHellfish likes this.
  6. DannyHellfish

    DannyHellfish

    Joined:
    Jan 20, 2014
    Posts:
    29
    @BoredMormon Thank you! Horizontal Layout group + Content Size Fitter did the job!