I’m checking out the beta for the first time and love timeline
I’m wanting to call a function at a certain point in the animation, I was hoping timeline events were a thing similar to the animation events but it doesn’t look like they are?
Wondering what you guys are doing for custom events being called in the timeline. Or if you even use timeline for this kind of thing.
EDIT: for e.g. , calling a new sequence after one has finished.
We’ve tried a few iterations with events, but nothing we were happy with, and it’s something we are looking into putting into a future release. For now, one option is to poll the state and/or time members of PlayableDirector from a MonoBehaviour.
This is actually a huge deal and big omission. Many uses of the new timeline will require the ability to trigger functions when animations are complete and it should not have come out of beta without it.
Back to square one again.
Whats even worse is you can right-click on the timeline track, select “Edit in Animation Window”… Add an event, bind it to a function… But the function never gets called.
Yeah, I just tried doing Animation events in timeline myself and found out they didn’t work.
In the meantime, can someone suggest a workaround? I’m not quite sure what “poll the state and/or time members of PlayableDirector from a MonoBehaviour” means exactly.
It means you should set up code in Update() that on every frame checks to see if the animation is done or not… or at the frame you wanted.
How the hell this is supposed to work with multiple timelines running in parallel with many of them nested within other nested timelines without looking like utter scribble I don’t know.
The whole point is that all of this was abstracted and managed by Unity… by having to write your own nested polling routines it makes it pointless.
Yeah, for now I’m just going to try making a list of unassigned Animation Events and iterate through them in update comparing time to PlayableDirector time and firing a function if PlayState is playing and the time of the event is equal to the PlayableDirector time. Still, I can see a lot of issues that will probably come up with this.
In this demo they have an animation that is to be played when a collectable game item has been collected by the player. Naturally at the end of that animation you’d destroy the object (or intelligent caching) instead of just having 1000’s of them hidden in your scene. Either way a script/trigger/event needs to be called.
If you notice, due to the lack of events / triggers they don’t do that. So the example they have is completely impractical. I just don’t understand how they they have released this out of beta.
Timeline is awesome for cutscenes, but not having events makes it obsolete for most gameplay purposes. The API for dealing with timelines is clunky at best, and when events work so smoothly in traditional animation clips it’s hard to find a reason to move to timeline.
til then im using a workaround to deal with this issue as well
like u, i want to trigger something/stuff at one point in the timeline, one or multiple times as needed
so what i did was create one or more animation clips that would animate through the timeline one or more checkbox exposed by a script i wrote placed on a dummy object that is monitoring the checkboxes
the animation clip would consist of 3 frames that animate the needed checkbox, off/on/off, with looping disabled
so for instance, the script would have a list of checkboxes like this 1-open door event, 2-play canvas animation, 3-move something
as all these checkboxes are monitored by the script, they call their corresponding functions as needed when ‘played’ by the timeline
its not as simple as the timeline having this feature built in, but try it out it works
ps: the reason the the setup is 3 frames consisting of off/on/off with looping disabled is to avoid the checkboxes firing incorrectly early on timeline load/initialization and to avoid looping problems that confuse the monitoring script
For some reason I wasn’t getting emails for this thread and missed all the comments.
Yeah it’s such a pain it’s not there. I used this to get around it:
TimelineEvent.cs (multiple events, time to fire during playback, type etc… )
TimelineHandler.cs (list of events that monitors the time to fire, and the current duration of the playable)
TimelineHandlerEditor.cs (an awful editor window that looks messy but lets me just create new events like a list)
I’m a complete novice so this is probably a terrible, expensive, inaccurate, pain in the ass to use method haha, but posting in case it helps someone like myself. Was just handy for triggering different UI during cut sequences in my case.
The handler:
public PlayableDirector playableDirector;
public List<TimelineEvent> eventList;
private void Update()
{
if (playableDirector.isActiveAndEnabled)
{
if (eventList != null && eventList.Count > 0)
foreach (TimelineEvent t in eventList)
if (playableDirector.state == PlayState.Playing)
{
if (!t.isActive)
if (playableDirector.time >= t.time)
t.FireEvent();
} else {
t.isActive = false;
}
}
}
Oh the rage … I’m there as well. Maybe it’s time for a different mindset. From another perspective: Let’s forget about what we would expect for a minute: A little gadget you can click to add an event, just like you used to do. Okay, now let’s envision it from a fresh mindset: OMG! We have an activation track now! So I says to myself … why not use it to generate an event that will cause another action to be taken, but wait … how 'bout just execute the event right there? Are you with me on this?
As a simple example, a hang this little script off of an object and drag the object onto the timeline as an Activation track, then adjust the clip to where you want the event to happen. If the timeline is a loop this will happen once per loop.
public class animEvent : MonoBehaviour {
void OnEnable()
{
Debug.Log("animEvent called at: " + Time.time); // put as much code as you want here.
gameObject.SetActive (false);// enabled = false;
}
}
Hmm, okay I can live with that. It even looks like a little ‘event gadget’ on the time line now.
Hope this helps someone else get past this.
note: I just figured out you want to zoom in on the timeline and make that activation clip very narrow so you it doesn’t get called multiple times per pass.
Good effort. But this can get messy quickly with the extra objects and references you have to set up. They need to make adding events to timelines the #1 priority besides critical bugs and introduce them in the next month or two. It’s become too acceptable to have to hack your way around Unity’s badly design limitations for too long.
Thanks. It’s my first post to the community. Would you agree maybe there’s two schools of thought on ‘messy.’ I.E. Some may argue it’s better to have the freedom to get messy rather than being constrained to one int, one float, one string, etc.
I came up with a solution but requires some extra steps. This method will ignore Timelines Animation features (the red record button) and instead just play Animations (old school Animation window that lets you use Events). For each timeline, you need a new animator controller and animation, you then add the event call you need in the animation, have it triggered by the animator, and have Timeline play the animation file. This requires the script you are trying to call be on the game object with the animator on it. If you want to use Timeline to edit the animation, you need to have that on a separate track and make sure to mute the animation when you are not editing it, it should be played on a separate (non-editable in Timeline) animation track.
Essentially what this is doing is ignoring Timeline and just playing the animation file, so Timelines role is to just start the animation and that is all. This causes problems with syncing because now, Timeline and the Animation are decoupled and just play, so if you want to pause or skip the timeline around, you need to do it to both the Animations Animator and the Timeline.
Here’s some code I wrote to do that, this is called as an event in the animation:
Well, there are different ways to currently do this as ‘workarounds’ of not having ‘Event Triggers’ on the Timeline:
When the Timeline is played via script, set off a ‘timer’ (Coroutine or Ticker, for example) that will then fire code when a certain time is reached. I actually do this in the talk (that you shared) for disabling player input at the beginning of a sequence and enabling at the end of the sequence (I get the Playable Director’s duration and use that as the wait time of a Coroutine)
Write a Custom Track/Playable that binds to a script and trigger a method on the script at the start or end of the clip.
Create an Empty GameObject that has a script with ‘OnEnable’ and ‘OnDisable’ methods in it that fire off different desired code/events. Bind this object to an Activation Track and move/adjust the clip to when you want to fire those methods. Ok, this last one is a bit ‘hacky’ but it completely works as a short-term solution. Im using it right now for a tutorial im putting together to disable/enable player input during a sequence.
So yeah, its a shame that there is no Event Track currently in 2017.1; but there are potential solutions to trigger methods at points in the Timeline. Its up to you which you want to use.
Write a Custom Track/Playable that binds to a script and trigger a method on the script at the start or end of the clip.
I was thinking about this one the other night. It’s quite “clean”. I bet someone has already written one or will shortly.