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

Rotating a UI element

Discussion in 'UGUI & TextMesh Pro' started by Whippets, Sep 27, 2014.

  1. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    What's the best way to rotate a UI element, namely a sprite?
    I've tried adding a simple update rotation script to it, but the sprite stutters and jumps. I wonder if that's from the RectTransform trying to keep the position.

    This is only for an updating circular arrow to show that something's busy.

    Anyone know of a better way to achieve this?
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,183
    what does your script do? Rotation works here.
     
  3. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    Hi Tim, I'm using a simple

    transform.Rotate(Vector3.forward *Time.deltaTime *100);

    in an Update(). The problem is a very jerky rotation, with the center stuttering from one pixel to another. It is aligned 0.5, 0.5
     
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,183
    Are you using pixel perfect? It will stutter between pixels if so because we try to align with the pixel boundaries.
     
  5. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    Interesting, thanks Tim. So I need pixel perfect for the clarity of text and 9 sliced sprites, but not for rotation. Yes, I've tried it and unchecking pixel-perfect works perfectly for rotation.

    What's the overhead of having a second Canvas just for the one or two items that need to be rotated, or is there a better method?
     
  6. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,183
    Adding a nested canvas for these rotating elements is probably the best option I think. It's not much extra processing.
     
  7. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    Nested? Ok, cool thanks Tim XD

    Tried a nested canvas, and a couple of things are immediately noticeable. The nested canvas has no options for pixel-perfect, but does not seem to take on the pixel-perfect setting of the parent canvas.
    For example, my main canvas is set to pixel-perfect, which causes jerky animation of UI elements; but the nested canvas which has no options for pixel-perfect, gives me smooth animation. Whilst it works for me, is this the intended behaviour for a nested canvas?
     
    Last edited: Oct 1, 2014
  8. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Nope thats not intended. we either need to expose it for nested or make it inherit the parent. Please report a bug so i can do it when i get back from vacation.
     
  9. PeteD

    PeteD

    Joined:
    Jul 30, 2013
    Posts:
    71
    Um if it inherits then the solution you just suggested i.e. using a nested canvas for the rotation elements will break will it not? I mean the parent would be set to pixel perfect so the child would by default then inherit the pixel perfect setting when in fact you want it not to.
    So isn't the only solution to expose the property on the nested canvas?

    Ignore me if I'm missing something obvious it's been a long day.
     
  10. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    bug reported: case 636781

    @PeteD - I think they're planning to make the nested canvas inherit by default, and expose the parameter so that we can choose not to inherit (as I want to).
     
  11. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Fun with nested canvases begins when you need to process events on them, coz using default raycasting priority, nested canvas graphics always has priority over other children of parent canvas even if children are rendered on top due to transform order.
    canvas.png (all buttons are pressed as expected except of red one where click is intercepted by green button)

    But having an ability to control pixel-perfect setting of nested canvas is a must for any layout with big scrolls or some moving parts.
     
  12. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    This is more of a separate bug then the one he was talking about and should have a bug raised about it.
     
  13. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Oh, I somehow thought it's a "by-design" behavior. I'll raise a bug soon.
     
  14. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Nope i dont think so, it very well might come down to a cant fix due to design but it sounds like something we should try to fix if possible so events "just work"
     
  15. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221