Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by xobookx · Jan 22, 2019 at 12:19 PM · animationanimatorchange colorcurrentpermanent

[SOLVED] start Animation with whatever value is the current one

Hey everyone, I'm trying to animate the color of an object.
It's supposed to change based on certain key presses.


I want to start the animation with whatever color is the current color of the object and transition to the new desired color. Then set this color permanently until another animation or function changes it.


The problem is that the animation always takes the color value that the object had at the moment I was creating the animation/keyframe and that the color reverts to the original color of the prefab (which I set to white) after the animation is finished.


Additionally I can't even at least make the change to be permanent by making an event at the end of the animation and setting the new color value via script, even though the function in the script gets called. It also always reverts to the prefabs original color.

Comment
Add comment · Show 4
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 DCordoba · Jan 22, 2019 at 05:37 PM 1
Share

why dont use color.Lerp? u can put this on a coroutine, a rough example, using fixedDeltaTime:

 public Color StartColor;//if you  want to have a starting fixed color, well not now so ignore this line
  public Color FinalColor;
  public float Delay; //delay seconds between the coroutine call and start changing 
  public float Duration;//duration of the transition between colors
  public $$anonymous$$aterial; //$$anonymous$$aterial of the object

 IEnumerator CC(){
     Imagen.color = StartColor;//ignore this too, set a fixed color on start
     yield return new WaitForSeconds (Delay);
     float Step = 0;
     while (Step<1.00001) {
         Step += Time.fixedDeltaTime / Duration;
         $$anonymous$$aterial.color = Color.Lerp (StartColor, FinalColor, Step);
         yield return new WaitForSeconds (Time.fixedDeltaTime);
     }
     yield return null;
 }

after put this on the script, replace where you use animation.Play() use a

 StartCoroutine (CC ());


avatar image xobookx DCordoba · Jan 23, 2019 at 03:42 AM 0
Share

@DCordoba I wish I would've seen your reply earlier but this is what I did and it worked now :D I'm so happy! But still it would be nice if they implemented something where you can just start with the variables that the Object currently has (as of while the game is running) because now it is hard to time the duration according to the animations speed (if e.g. i change the animations speed for different situations)

EDIT: It works as intended but I like to fully understand what I write. Right now I don't understand why we need to do this: yield return new WaitForSeconds (Time.fixedDeltaTime); could you explain that to me please?

avatar image DCordoba xobookx · Jan 23, 2019 at 04:45 AM 1
Share

Well, the coroutine is similar to a thread, ("similar" in purpose and behaviour) the ienumerators could be seen like the list of execution of the thread.

yield return gives a returning result (as return do) but keeps executing inside the "tread" so the execution don't abandone the ienumerator.

WaitForSeconds indicate to the coroutine to stop execution for the following amount of time, similar to wait(); on the threads...

And Time.fixedDeltaTime is the time to the physics are uptaded (it is fixed on execution, difference with DeltaTime, who depends of frames per second) and can be changed on inspector options.

So with this instruction we are saying to the coroutine, ok, lets wait the next fixed amount of time, before continue changing the color, it make the coroutine have a finite, equals, steps to make the slow transition, the number of steps are given by Duration/Time.fixedDeltaTime

Edit To Clarify: the WaitForSeconds just stops the current coroutine execution, (this thread? execution) the rest of "independent" tasks (scripts outside the Ienumerator) continue as usual, without being affected.

Please not confuse it with the inverse Time.fixedDeltaTime/Duration, this gives the percentage (scaled from 0 to 1) completed on the current step, the sum are used to get the total percentage completed, and given to Lerp to calculate the color on this step.

Well, you will see each steps slow or fast depending of the fps at the moment, but will take the same amount of time (duration) in "real" seconds.

Show more comments

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

261 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 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 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 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 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 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 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 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 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 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 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 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

2D Animation does not start 1 Answer

Handling Build-up of Root Motion Errors Over Time 2 Answers

Animate an Object by letting it play out in when I press play? 0 Answers

My player won't jump? 1 Answer

Animation stops rotation 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