Search Unity

Using Timeline to call a function?

Discussion in 'Timeline' started by Hazneliel, Jul 12, 2017.

  1. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    306
    When I first heard of timeline I imagined I would be able to call functions on certain objects, for example when reaching a certain frame to call a function on an object so it does something.

    Is this possible, it would make a lot of sense to be able to do something like this.
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Right now, the only way is to write custom playables that call functions. It's something we have spent a good deal of time investigating, and will be trying to release something in a future version that does this.
     
    TheWarper likes this.
  3. rneron1

    rneron1

    Joined:
    Jun 16, 2017
    Posts:
    9
    Insane! Keep going up at that rate :) Love the improvement of Timeline!
    I'm waiting for Demo projects and This particular feature of calling a function without doing 4 scripts to do it eheh!
    Thanks!!
     
  4. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    306
    Thanks, will look forward this feature in the future.

    Hey, do you know how it has to be currently done? Is there any example of tutorial somewhere?
     
  5. GilbertoBitt

    GilbertoBitt

    Joined:
    May 27, 2013
    Posts:
    111
    So the easy way is create a custom playables with a custom event so this way we can call any function we desire?
     
  6. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
  7. MattFS

    MattFS

    Joined:
    Jul 14, 2009
    Posts:
    219
    Hello
    Sorry to necro an old thread but it was relevant to this...

    So, I'm trying to look into Timeline as a generic 'event executer' but find it's not very flexible at the moment.

    For example... I'm able to drag an AudiClip from Project into a scene Timeline, but NOT a prefab? So, how would we spawn custom prefabs during a timeline?

    Maybe I'm seeing Timelines the wrong way... so I'm posting here to try and get a better understanding of where it's heading and where Unity see's it's function in a project.

    Here's an example of what I want to achieve....
    Event: Ogre Enemy Slams Club
    - Start main event at explicit location (not just at transform the Director is on)
    - Play slam animation
    - Spawn VFX Prefab at precise frame
    - Play audio at precise frame
    - Call numerous scripts (as this would be live, gameplay event)
    - Broadcast messages (the camera might listen and shake from the slam)
    - Fire off sub-events
    - Fire callbacks for event (started, finished... etc)

    That's one example where a simple gameplay event (an attack, a jump, firing a weapon) needs to bring together many assets at once.

    But I was not able to do this with Timeline/Directors... I hope I'm just missing some basic flags or setup as I'd really like to start using an official tool for this, is Timeline meant for these sorts of sequenced events?

    Years ago I wrote a tool just for this... it is it's own independent asset, so you can fire it whenever and whereever you want, it can spawn objects, destroy objects, play animations, play sounds, call script functions... so I'm hoping to get a better understanding of what the purpose of the Timeline tool is as i'm on the fence at the moment whether to invest time into my tool, or to start using Timelines for all events.... if Timeline is meant to be an all round event scheduler, then I'd much prefer to use a Unity supported feature! :)

     
  8. gekidoslayer

    gekidoslayer

    Unity Technologies

    Joined:
    Sep 27, 2016
    Posts:
    134
    Agreed that events are a must-have feature, but it's relatively easy to add your own event broadcast system using Activation tracks. It's not perfect, but does the trick.

    What I've done for my own purposes is basically a script that fires events in 'OnEnable()' and 'OnDisable()' - I attach this to a game object in my scene and setup activation tracks to activate the game object to fire the event.

    In this way, the events aren't being fired by Timeline, but by the gameobject, which lets you do whatever you want in your activation / trigger script (and use whatever messaging system you want), all you need to do is wrap it in an OnEnable() {} MonoBehaviour method

    It's not perfect, but you can make the event trigger system as customized as you want with this kind of system.
     
    IrvineLee, TextusGames, Lefko and 7 others like this.
  9. MattFS

    MattFS

    Joined:
    Jul 14, 2009
    Posts:
    219
    Hey Mikew - thanks for the reply, your approach makes sense in that the Timeline just becomes a toggle for more complex (or not) behaviours fired off in their OnEnable... and ultimately, the same end result could be achieved. Just from a workflow point of view it would be nice if this is all under one roof/tool... but good to know there's an approach that works. Cheers!
     
  10. gekidoslayer

    gekidoslayer

    Unity Technologies

    Joined:
    Sep 27, 2016
    Posts:
    134
    I agree that it should be built in - and I know the Timeline team is fully aware of this (#1 feature request I'm pretty sure), but one advantage of doing this through activation tracks is that you aren't limited to a specific event / messaging system - because it's just activating a monobehaviour via OnEnable(), you can use whatever custom messaging framework you want to for the actual event sending mechanism. I typically use a custom broadcast system for example, so I actually think I prefer to use the system I've described over a custom system. But YMMV - and I may change my mind once the 'official' version comes down the pipeline ;}
     
    AviarLabs likes this.
  11. snoche

    snoche

    Joined:
    Feb 22, 2010
    Posts:
    82
    Is this now possible with 2019.1 and signals?

    What I want is to be able to call some functions like in the "UI Buttons event triggers" but from the timeline.
    Basically a way to display calls to public c# functions inside the timeline.
     
  12. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
  13. snoche

    snoche

    Joined:
    Feb 22, 2010
    Posts:
    82