When playing a timeline how to detect it has been completely played? I tried to compare the time and duration properties but when the timeline wrap property is set to “none” the “time” value will never be equal or greater than the “duration” value and will be reset to 0 when the timeline is completed.
Does Unity consider to add event to that ? Because even if checking properties could work with other wrap mode it means that the code that want to know when the timeline is completed should be a Behavior in order to check in the Update method or call a Coroutines. I know it’s possible to call Coroutines frome an other Behavior and for sure you could come with another solutions, but events would be very convenients.
Ok, but when “wrap” property is set to “hold” the state stay forever to “Playing”. So there is no “one” solutino to check that. Depending of the “wrap” property value you have to check the state or compare time and duration. Not realy convenient.
As far as I know there is no guarantee that event will get fired. There’s no guarantee an event will be processed. So this is not reliable with low framerate or hiccup from OS, etc.
You are correct. It sounds like the best course of action is a listener on the playable director that triggers when the playstate changes (completed), when the time stays the same (hold), or when the delta time goes backwards (loop).
By the way, is it normal when the “wrap” property is set to “hold” the state is still “playing” ? I can understand why, it’s like the last frame is “looping” but not sure why it’s a good thing. Is cool to be able to maintain the last frame state but would it not be possible to do that in a “permanent” way that would prevent to let the director playing again and agin ?
Yes, I know. But what bothers me here is that you have to check with different type of conditions depending on that mode. Not really intuitive nor easy. I really want a simple event that could be triggered when a timeline is complete.
Does this mean only 1 action can be attached to onPlay? As in: timeline.onPlay = () => Debug.Log(“do something”);
That works, but that means you can’t just listen and unlisten for the event … you need to make sure you’re not stomping something else. Also, doesn’t most of the Unity API use events?
Okay, that works then. Don’t get me wrong, I use Actions and Funcs all the time, they’re great … but I’m still curious what the reason is behind using actions here instead of events? Since a lot of other Unity systems use events for this kind of functionality (ie: VideoPlayer), why is this being built differently? I would have thought consistency between different parts of the Unity API would have been enforced, especially when we’re talking about the same thing from a user experience (hooking into an onComplete, or any other “event”).
Just wondering if there was something specific that warranted the difference, or its a preference of the team working on this.
Noted! I agree we should have a event for Timeline completion. I am not sure having onClipEnter/onClipExit events is the right solution, but we definitely need a robust way of knowing when a clip is playing or is finished.