Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
3
Question by DavidDebnar · Feb 01, 2014 at 10:41 PM · animationreflectionanimationcurvepropertygetsetter

Use AnimationCurve to animate a property?

Hey guys. I have a system which generates some AnimationCurves, using .SetCurve assigns them to an AnimationClip, which is then played on loop. It works fine, although I haven't been able to animate properties with custom get/setters.

I have a variable called Distance, which, when changed, updates the size of a BoxCollider2D component. This works when either set directly 'Distance = 10' or via Reflection (which I suppose is what AnimationCurves use). Problem is, that I'm guessing, that AnimationCurves use FieldInfo to to cache the Reflection and not PropertyInfo, which makes get/setters with side effects not work.

To sum up: Am I right thinking that Curves only support fields? If no, then what's causing the issue - the solution?

I'm open to any other ideas too.

Also, if you know of a way to detect variable change, which doesn't involve a get/setter, then I'd be pleased to now. I thought about caching the old value and than have an Update loop running, but I'm trying to optimize as much as possible and having a loop running just to check if a variable has changed seems kinda ridiculous to me.

 public float Distance 
 {
     get
     {
         return m_Distance;
     }
     set
     {
         if(m_Distance != value)
         {
             m_Distance = value;
             BoxCollider2D b = GetComponent<BoxCollider2D>();
             b.size = new Vector2(m_Distance, b.size.y);
             b.center = new Vector2(m_Distance / -2, b.center.y);
         }
     }
 }
 public float m_Distance;

Thanks,

--David

Comment
Add comment · Show 1
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 potti · Oct 16, 2018 at 08:38 PM 0
Share

I am dealing with a similar issue right now. I looked into some unity internals and it seems that predefined components, like the sprite renderer actually have properties (not fields) that can be animated, but i do not see a way to allow custom properties to be animated.

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

22 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 avatar image

Related Questions

Unity4.5 AnimationCurve - Is the property "_MainTex.rotation" valid ? 0 Answers

Animation property for box collider doesn't work until I press the small record button twice 0 Answers

code animation on multiple properties using one AnimationClip 1 Answer

Adding different animations to the Unity Locomotion System 0 Answers

How to edit animation curves for a humanoid animation? 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