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

Anchors don't work with scaled objects

Discussion in 'UGUI & TextMesh Pro' started by Pangamini, Oct 9, 2014.

  1. Pangamini

    Pangamini

    Joined:
    Aug 8, 2012
    Posts:
    54
    I've noticed that rectTransforms and their scale won't work well with the anchoring system. The anchors will work with the anchored rect as if its scale was 1;
    I've reported the Bug here: http://fogbugz.unity3d.com/default.asp?638219_f985totprk95vfmt, i hope it won't be ignored (this is a show stopper for me).

    Even if it could be potentially hacked around using anchors that are scaled proportionally, there's this artificial bound that won't let me set anchors outside the parent rect (which is a shame, this could be useful in other cases, so maybe unlocking this would be a good idea)
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    This is by design. Anchors control the unrotated, unscaled rect. Rotation and scaling is added on top of that.
     
    el_nuru likes this.
  3. Pangamini

    Pangamini

    Joined:
    Aug 8, 2012
    Posts:
    54
    I am sure that if you look at the example i posted with the bug report, you willl see there is no way this is an intended behaviour. But i can't upload it to forums now, i am on different machine

    The thing is, scaled UI.Image inside another, for example, UI.Image, will get misplaced after the parent rect has changed (relatively to its intended anchors). So when i want to set scale to sliced sprite (to scale its borders and corners), it's unusable together with anchoring, making the scale property useless
     
    Last edited: Oct 10, 2014
  4. Pangamini

    Pangamini

    Joined:
    Aug 8, 2012
    Posts:
    54
    And in case i misunderstood something and this really is an intended behaviour, is there any other way how to scale borders of sliced sprites? (without modifying the actual texture width and height of course)
     
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    I have and I can assure you that it is intended behavior.

    Like I said, the anchors affect the unscaled, unrotated rect. It's expected that the effect on the scaled and rotated rects can be unintuitive. You can enable the Blueprint mode in the Inspector (the toggle button that has a marquee rect on it) to make the handles corresponds to the unrotated unscaled rect, to better be able to see what's going on.

    The scale property scales everything up or down uniformly, like for any other GameObject. It's definitely not recommended to use for layout purposes, but it can be useful for various animated effects.
     
  6. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    Yes, you can modify the pixelsPerUnit setting in the texture importer for the sprite.
     
    Pangamini likes this.
  7. Pangamini

    Pangamini

    Joined:
    Aug 8, 2012
    Posts:
    54
    Ah I missed that one. Thank you very much for the reply!