Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

New in 2019.1 - Marker Customization

Discussion in 'Timeline' started by julienb, Dec 7, 2018.

  1. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    112
    A new item has appeared: markers!

    A marker is new item that can be added to a timeline. It is used to represent a point in time.
    Markers can be added and manipulated on a timeline the same way as clips; selection, copy-paste, edit modes etc. should work. A markers also has a specialization, just like clips (Animation Clip, Activation Clip, Control Clip, etc.). In 2019.1, Timeline offers its first built-in marker: Signal Emitter marker. See this thread to know more about signals.

    It is also possible to write custom markers!

    How to create a custom marker

    In order to let timeline know that you have a new type of marker, all you have to do is to create a class that inherits Marker.

    public class CustomMarker : UnityEngine.Timeline.Marker {}


    That’s it! This custom marker can now be added on any track and on the timeline marker area.

    At this point, the custom marker is only a visual item on the timeline. This means that this marker cannot invoke code when triggered. That doesn’t mean it is not useful; a marker can be a snap point or a chapter. It is also accessible through the Timeline API in editor and at runtime

    How to create a custom marker that will invoke code

    In order to have a marker trigger something, it needs to implement the INotification interface.

    public class CustomMarker : UnityEngine.Timeline.Marker, INotification
    {
    public PropertyName id { get { return new PropertyName(); } }
    }


    Implementing the INotification interface will tell timeline that the marker will need to react when triggered.

    The INotification interface is part of the Playable notification system. Each marker that implements INotification will have a node added in the timeline’s Playable Graph.



    To make things clear, here’s a table of the particularities of the different ways to create custom marker:
    upload_2018-12-7_17-13-27.png

    When a INotification node in the Playable Graph is sent, the PlayableOutput will receive it. One last piece will need to be added in order to process this notification.

    public class MessageReceiver : MonoBehaviour, INotificationReceiver
    {
    public void OnNotify(Playable origin, INotification notification, object context) {}
    }


    The PlayableOutput will need to have a CustomReceiver component in order to receive and process the INotifications.

    Here’s a summary of what you need to do if you want to invoke code with your custom marker:
    1. Create a class inheriting from Marker and implementing INotification.
    2. Create a component implementing INotificationReceiver.
    3. Add this component on the correct Gameobject
      • If your custom marker is on a track, add the component on the track’s bound object.
      • If your custom marker is on the timeline itself (the timeline marker area), add the component on the Gameobject that has the PlayableDirector component.
    In order to show you what is possible to do with custom markers, I created Message markers. These markers act like Animation events, but directly in the Timeline. See this Github repo to download the project and see how I did it. The relevant code is here (the rest is just inspector code).

    One last thing...

    We just saw that we can customize the behaviour of a marker. But that is not the only you can do; it is also possible to customize a marker’s appearance. It is not yet available in 2019.a11, but it will release in 2019.1. Stay tuned.
     
    Last edited: Dec 7, 2018
  2. AndrewKaninchen

    AndrewKaninchen

    Joined:
    Oct 30, 2016
    Posts:
    53
    Is there a particular reason as to why this example uses custom code to extract available methods from the gameobject in question instead of using a regular UnityEvent? Is it only to show that you can directly reference the bound object?
     
  3. AndrewKaninchen

    AndrewKaninchen

    Joined:
    Oct 30, 2016
    Posts:
    53
    Ok, I get it, UnityEvents don't have a way to insert context in them, so if they're in an asset (like something from a Timeline, which obligatorily resides in an asset), they can only see Assets.

    UnityEvents really should get a little power-up. They can only have a single parameter, you need to derive from them because Unity can't serialize generic stuff, and now this as well.
     
    Last edited: Dec 8, 2018
    GameDevCouple_I and Vectrex like this.
  4. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    425
    From my perspective:

    The sample is more demonstrating you can build the old (and kinda not great, what with the SendMessage call and fixed argument types) animation events functionality on Timeline if you really wanted to. This could be useful if you're moving from a cutscene controlled by an Animation clip to a cutscene controlled by a timeline and you wanted to salvage code that relied on the old events system before fully migrating to a cleaner setup with signals or other custom marker types specific to your use case (and likely more performant that this by a good margin).

    UnityEvents are just a way to serialize parameters and delegate references to other objects in the editor, they're not a great solution for completely decoupled communication due to way delegates work. The subscriber has to know about where the UnityEvent's containing object is before subscribing/unsubscribing. On top of this, Delegate invocation is often the slowest type of call in the .NET framework and UnityEvents add another layer on top of that.

    The signals way is just a contract using the Signal Asset as a token that maps to a function call. This allows a more complete decoupling. That said I'll need to get on the 2019.1 alpha at some point and actually get a feel for it before I go deeper into the pros and cons.

    I can see where your frustration lies, the signals way is very different than what seems to be intuitive but there may be performance/implementation simplicity reasons for going that route that remain unseen what with all of this being brand new.
     
  5. AndrewKaninchen

    AndrewKaninchen

    Joined:
    Oct 30, 2016
    Posts:
    53
    Sure, that looks pretty much like the idea, even if only to serve as an example:

    Nothing much to add to that, it was more that I didn't really understand the reason as to why not use UnityEvents in a case in which they'd have been able to fulfill exactly the same purpose. That is, until I realised why.

    That could easily be solved, I think, by extending the UnityEvent API to allow for it to have basically that same UI, but also to have context injected into it. In this case, it could even use the kind of references the Timeline Asset itself uses, with Exposed Properties which are populated through the Director Component.

    I haven't read the UnityEvent source code yet, and by a glance it does seem to be quite intricate, but it surely is far from being one of Unity's most complex features. Given it's importance, I do think it's worth the investment into improving it.

    See, that I don't buy as a problem. At all. At which order of magnitude in call counts would you have to be for your timeline events to actually become a performance problem? You'd need to have an insane amount of events at the same frame, which makes no sense at all if you think about most if not any use case for Timeline. And, of course, you could write your own call system if you are in one of the unlikely edge cases.

    Yes, I realize that as well. I even mentioned it in the other thread. Although I do lack to see the reason as to why that much decoupling would be necessary. As I mentioned in the other thread, the current way the system does it is by creating an insane list of signals with only their names to help identify them. I think it'd be much better if they could lie in Timeline Assets themselves, at least. That way, at least you'd have the context in which said signal name is supposed to happen.

    The problem with this approach is it forces all of the context to the callee, leaving none of it to the caller. In some cases, it'd be very useful to be able to divide it between the two, as my example with "A bunch of slighly different explosions" tries to illustrate.

    My frustrations don't lie simply on the Signal system itself (although I've already explained a bit of the problems I immediatly see in it in the other thread). It's more on the fact that said complexity could be opt-in. There are a ton of usecases in which said complexity isn't needed at all, as a lot of sequences can be directly mapped to the scene they should reside in.
     
  6. AndrewKaninchen

    AndrewKaninchen

    Joined:
    Oct 30, 2016
    Posts:
    53
    Something else I always forget to say:

    There is no visual cue for a selected marker in the Timeline view. Is it just a bug for me or was this never present? Shouldn't it be blue when selected, like every other selectable piece of the UI?
     
  7. Alexees

    Alexees

    Joined:
    Nov 8, 2017
    Posts:
    113
    @julienb could you quickly explain what a Marker Track does? It seems to be related, talking about Markers and all, but it's never mentioned, explained anywhere, used...
     
  8. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    112
    A marker should be white when selected. upload_2019-1-7_11-42-5.png
     
  9. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    112
    Marker Track is a utility class that you can inherit from when creating custom tracks. It is a track that does not accept clips.

    By the way, the Marker Track should never have been shown in the Add menu:(. It's a bug that appeared right before releasing the alpha version.
     
  10. Alexees

    Alexees

    Joined:
    Nov 8, 2017
    Posts:
    113
    Hihi, I thought something like that was the cause.