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 /
  • Help Room /
avatar image
1
Question by Michkkael · May 24, 2017 at 07:42 AM · timeline

How to detect end of a timeline (C#)

Hello all :)

I'm getting starting with Timeline, the new feature of Unity, and it's working like a charm!

I'm trying to detect the end of a timeline. So far, I found this :

_director = transform.GetComponentInChildren<PlayableDirector>();

And this in a coroutine :

 if (_director.playableGraph.IsDone())
 {
     OnEnd();
 }

Actually, it's not working... (Object reference not set to an instance)

I'm looking for a more reliable way to do this. Do you know if there's any events? Maybe this? But I don't know how to get the PlayableBehaviour instance from the PlayableDirector.

Thanks a lot for your help!

[EDIT]

I found this way but I'm still not fully satisfied :

 public IEnumerator CheckEnd()  
 {
     while (Math.Abs(_director.duration - _director.time) > 0.2) 
     {  yield return new WaitForEndOfFrame();  }   
     OnEnd();   
  }  
 
 public void OnEnd()   
 {  
     Debug.Log("On end");  
 }
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 SpaceManDan · May 24, 2017 at 11:55 AM 0
Share

What are you wanting it to do now? I'm sorry, but I don't know what you're question is. Does it work? yes. Is it reliable... yes? I mean, how is it not working. Then we can help.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by CapnCromulent · Jul 12, 2018 at 10:12 PM

As of 2018.1, you can listen for an event on the PlayableDirector: https://docs.unity3d.com/ScriptReference/Playables.PlayableDirector-stopped.html

Comment
Add comment · Show 2 · 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 unity-marcus · Jun 01, 2019 at 01:15 PM 1
Share

Seems like the event is broken in Unity 2019.1.4f. I am going to use the polling solution.

avatar image rcabot unity-marcus · Mar 12, 2020 at 12:28 PM 0
Share

you're right, it does seem to be broken - I've personally used signals for a bit more flexibility and less polling, for anyone who comes across this

avatar image
0

Answer by deneme09 · Sep 07, 2017 at 11:13 AM

I've been trying to solve this problem for a few hours and I solved it! You can try this code.

 if (GetComponent<PlayableDirector>().state != PlayState.Playing)
 {
     //your code
 }

I hope it works.

Respect from Turkey :)

Comment
Add comment · Show 2 · 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 Modona · Mar 24, 2018 at 12:03 AM 0
Share

I thought it is not good idea to put such code to check it every frames,why not try to add a animation event at the last of the timeline

avatar image Klamore74 · Sep 18, 2020 at 09:36 AM 0
Share

I used this approach in the past but I had a bad side effect: if the application lost focus, the play state change.

So is not working in that case.

avatar image
0

Answer by pantoygames · Aug 20, 2021 at 01:55 AM

Start this coroutine

 private IEnumerator PlayTimelineRoutine(PlayableDirector playableDirector, Action onComplete)
 {
     playableDirector.Play();
     yield return new WaitForSeconds((float) playableDirector.duration);
     onComplete();
 }








Comment
Add comment · 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

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

112 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

Related Questions

Animate one axis with the new timeline 1 Answer

Does timeline clip support multi-object editing? 0 Answers

Is it possible to add more than one clip to the track via Script? 0 Answers

Is this possible on unity to change any video face with a real person face? 1 Answer

TimeLine Issue with Game Object transform 2 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