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. Dismiss Notice

Why did they limit the anchors to [0, 1] ???????

Discussion in 'UGUI & TextMesh Pro' started by Helical, Dec 4, 2014.

  1. Helical

    Helical

    Joined:
    Mar 2, 2014
    Posts:
    50
    If We could define anchors outside the bounds of parents it would be so useful !!!

    The most common constellation of anchors (that I use at least) is when anchors surround a UI element. That way its size stays relative to its parent. But what if I want that UI element to be outside the parents bounds? like waiting there to hop in??? then I could just move the UI element away, but then the anchors will not be surrounding it, and that means that it wont rescale and reposition properly on different resolutions.
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Can you explain your use case a little bit more thoroughly?
     
  3. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    one way to get around this is to use an empty gameObject in between them and move that instead
     
  4. Helical

    Helical

    Joined:
    Mar 2, 2014
    Posts:
    50
    I have a canvas representing the screen.

    I want to make a small window slide/lerp into it from outside the canvas.

    So naturally I position the small window outside the canvas.

    I want it to stay there no matter resolution the screen goes into.

    oh wait, I CANNNNNT.


    because when I place an element outside the bounds of an element. that is recorded in pixels as offset from the natural anchor position. and anchors are bound to the limits of its parent.

    I dont understand why would this system benefit from such a restriction!
     
  5. Helical

    Helical

    Joined:
    Mar 2, 2014
    Posts:
    50
    once again that wont rescale properly, as the things that I do have to work in web and android and bunch of other platforms. no matter how you place it. if an element is outside the bounds of any of its ancestors. then the offset will remain in pixels no matter what the resolution is.
     
  6. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683

    works for me...
     
  7. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    556
    I found that you actually can set the anchors to be outside the [0, 1] range through code, though the second you touch it in the editor it snaps right back. It really seems to be a purely Editor-induced limitation of the system, which I agree is annoying and not serving any real purpose.

    If you want a quick make-shift solution that Probably Works For You™, feel free to check out my (free, poorly named) uGUI Tools editor script.
     
    ModLunar and Helical like this.
  8. Helical

    Helical

    Joined:
    Mar 2, 2014
    Posts:
    50
    Yeha I already have your uGUI tools, I like them alot btw. So your saying that I should do the "Anchors to corners" on every UI element awake call?
     
  9. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    556
    That's one way! I was more thinking along the lines of editor scripts/ extensions so you can set the anchors before-hand through that. I.e.: With uGUI Tools you could move an element outside its parent and call "Anchors to Corners" while editing your scene. I'm fairly sure that works?
     
  10. Helical

    Helical

    Joined:
    Mar 2, 2014
    Posts:
    50
    nope, anchors get clipped.
     
  11. braindx

    braindx

    Joined:
    Dec 15, 2013
    Posts:
    2
    +1 that this is super frustrating.

    EDIT: Fun fact though. You can edit it to be outside the [0,1] range if you use the curve editor.
     
    ModLunar likes this.
  12. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    What's wrong with setting the position outside the screen? Anchors aren't meant to be outside the screen, it's not how they are supposed to work
     
  13. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    Hey,

    I am creating a tool to allow you to go past the clipped range of the current handles. It has pretty much the same workflow as the current ones. I will most likely just post it for free. You can see the early system in the image.

     
    Last edited: Jan 2, 2015
    ModLunar likes this.
  14. Helical

    Helical

    Joined:
    Mar 2, 2014
    Posts:
    50
    Because if its set outside of the screen, and then you increase the screen size (maybe a higher resolution screen) then it can go in and wont stay in place relative to where you placed it. which makes creating GUI elements that come into existance by being slided from outside very Awkward to make properly with portable screen resolutions
     
  15. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    Not true. Set the anchor to the right of the screen, set the position X = width, and it will always be outside the screen, no matter the screen size.

    And to slide it in, change the position to 0.
     

    Attached Files:

    • UI.png
      UI.png
      File size:
      40.7 KB
      Views:
      976
    Last edited: Jan 2, 2015
  16. petrapparent

    petrapparent

    Joined:
    Jun 6, 2011
    Posts:
    28
    Hi Revolter,

    Setting it X=width is a pain if the resolution or orientation changes. Anchor points outside [0,1] make a lot of sense.

    Petr
     
    rakkarage likes this.
  17. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    ya i set mine to 3000 but when i run it on apples new 5k monitor it still shows up :(
     
  18. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    1) How do you set the anchors?
    2) What version of Unity do you have? Do you have the Canvas Scaler Script on the Canvas?

    upload_2015-1-3_11-0-58.png
     
  19. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    Setting X = Width works on any resolution if you have the Canvas Scaler script on the Canvas. You can implement everything described above in this thread without setting the anchors outside 0 and 1.

    Let me know what you failed to implement, and I'll explain how to do it properly.
     
    rakkarage likes this.
  20. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    ya i was just being facetious... was trying to manufacture a scenario where offsetting position by 3000 like i do in the gif above would not be sufficient apparently i failed. thanks :)
     
    Revolter likes this.
  21. braindx

    braindx

    Joined:
    Dec 15, 2013
    Posts:
    2
    Let me give you a scenario:

    Let's say I want a panel that is 20 pixels inset from the screen's borders. To do this, you want your anchors set at the corners of the screen and left/top/right/bottom set to 20.

    Now, I want to animate that panel from outside the right hand side of the screen to the center of the screen. Wouldn't one want to animate the anchors from [1,1]->[2,2] (offscreen) to [0,0]->[1,1] (onscreen)? No amount of fiddling with width/height will do that for you since it doesn't have a fixed width/height.

    Anchor points outside the [0,1] range are meaningful and useful. That's the point.
     
  22. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    We've implemented support for dragging anchors outside of the bounds of the parent rect when holding down Control (or Command on Mac) - the same key that disables snapping.

    It may take a few patch releases before the code makes it to a release.
     
    codxr, ModLunar, 5argon and 3 others like this.
  23. Helical

    Helical

    Joined:
    Mar 2, 2014
    Posts:
    50
    Glad to hear.