• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Bigproblem01 · Mar 24, 2015 at 04:44 PM · animationuirecttransformrectmechanim

anchoredPosition in mechanim locks my axis

Hello,

I have a UI Text object. I affect it in several ways:

  1. I move it down with mechanim affecting its pivot

  2. I scale is up and down several times using mechanim affecting it's scale

  3. I shake it (move it inside unitSphere on y/x axis) with the below script

      void Update () 
         {
             ShakeStandBy ();
         }
     
         void ShakeStandBy()
         {
             if(shakeIntensity > 0)
             {
                 transform.position = originalPosition + Random.insideUnitSphere * shakeIntensity;
                 shakeIntensity -= shakeDecay;
             }
             else
             {
                 transform.position = originalPosition;
             }
         }
    
    

"1.", "2." and "3." all work fine on their own.

Here's the problem: In "2." I also need to affect the anchoredPosition because by that time the text is moved with "1." and its pivot is modified, so to counter that I also affect anchoredPosition in my scaling animation which gives the desired effect - the text is scaled from its CENTER and remains in the desired location. If I were to counter this effect by affecting pivot instead, the scaling would not happen from the center but from the top (since I moved the Text DOWN).

As soon as I use anchoredPosition in my animation, the shake stops working on the y axis as if it's locked and only works on x axis. I don't even have to run that animation, it's sufficient to have a state in the animator with this animation (that affects anchoredPosition somehow) plugged in, and the shake won't work. If you unplug it, it's works normally again.

I tried rewriting the shake function with GetComponent().anchoredPosition but I get the same result. I spent the entire day trying various workarounds and nothing solves this issue.

Does anyone know why do I get such behaviour?

Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by curiouspers · Mar 24, 2015 at 06:22 PM

Yup, mecanim just works this way, move your ShakeStadBy() call to LateUpdate instead of regular Update. I fixed my animation problems this way. And this maybe interesting: http://docs.unity3d.com/Manual/ExecutionOrder.html This is for 2) and 3).

For 1) and 2) you can also try using animation layers and play with override value.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bigproblem01 · Mar 25, 2015 at 10:11 AM 0
Share

You know what the funniest thing is? I have that picture of the execution order on my desktop for 3-4 months already. And I got so used to it being there that I stopped perceiving that it actually holds any kind of information and by the gods man did you save me a lot of further guesswork.

Thank you!

Still, It's very weird and uncomfortable that if I have ANY animation in mechanim affecting ANYTHING, that THING will be locked in place and I won't be able to manipulate it unless it's in LateUpdate and sometimes I even have to manually disable the animator so it doesn't snap the position/scale/whatever back to it's place as soon as the action in LateUpdate is finished. It looks like a bug. I mean if the animation is not playing at that moment, why the hell are its values (whatever it animates) locked in place?? This looks like a bug to me

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

RectTransform returning incorrect rect bounds 0 Answers

UI How to configure Left And Right. 1 Answer

How to animate UI rect transform which works for all resolutions 1 Answer

Changing the size of the RectTransform's rect 0 Answers

Reusing SpriteRenderer animations in UI 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges