Search Unity

UI objects overlapping

Discussion in 'UGUI & TextMesh Pro' started by inthemilkywat, Dec 21, 2016.

  1. inthemilkywat

    inthemilkywat

    Joined:
    Dec 29, 2013
    Posts:
    56
    I have a pool of UI objects that I am using to show name of items that are on the ground. So every time a item drops, I take one of the UI objects from the pool and place it on the item using WorldToScreenPoint. The problem I am having is that when there are a bunch of items clustered on the ground, the UI for each item overlaps. I want them to stack on top of each other if overlapping. Not sure how I can fix this issue. Here is an image of the problem.
     

    Attached Files:

    Last edited: Dec 21, 2016
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    You have to sort the labels.
    Place the first label (that one that is the lowest on the screen or maybe nearest to the camera in world space like to normally wood.
    The other you have to check if the rect that they would be displayed overlapping with any other ui element that already there.
    If its overlapping move element up so that they do not overlap anymore.

    One useful function is,
    https://docs.unity3d.com/ScriptReference/Rect.Overlaps.html

    (This all is if you are doing you ui all in one canvas)
     
    Last edited: Jan 2, 2017
    SimonDarksideJ likes this.
  3. inthemilkywat

    inthemilkywat

    Joined:
    Dec 29, 2013
    Posts:
    56
    Thanks for the help. I got it working.
     
  4. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    Hey, I'm working on the same thing atm, but how did you fix this?
    I'm trying with boxcolliders, but I'm getting serious performance issues.

    Not really sure how you would detect if they overlap by using rect.overlaps, cause you'd need to reference each specific label.
     
  5. Poinball

    Poinball

    Joined:
    Feb 23, 2016
    Posts:
    42