Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Feedback [ Bugs ] Animation Tracks - Drag into Inspector and checking for last keyframe

Discussion in 'Timeline' started by KarlKarl2000, Jan 15, 2020.

  1. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    609
    @julienb @seant_unity
    I'm new to timeline, so things are a bit confusing. Please bear with me :confused:

    I hope someone can help me out.

    #1 Is there a way to know when a Timeline "Animation Track" has finished reading it's last keyframe? Can we detect marker \ signal calls via code?

    I get errors when putting this into my C# script.
    Code (CSharp):
    1. public class customMarker : UnityEngine.Timeline.Marker, INotification { }
    2.  
    3. public class signalGest : MonoBehaviour, INotificationReceiver
    https://forum.unity.com/threads/new-in-2019-1-marker-customization.594712/

    Code (CSharp):
    1. The script 'SignalMarker' does not derive from MonoBehaviour, but has been added to Game Object 'Image'. Please remove the script from the Game Object to avoid crashes.
    screenshot.10.jpg

    screenshot.11.jpg



    I don't see on the API page for Animation Track about .Stop() or .Play()
    https://docs.unity3d.com/2018.3/Documentation/ScriptReference/Timeline.AnimationTrack.html

    In this example I'd like to know at runtime, when "Image" reached frame 60 and "Text" reached frame 90.
    screenshot.7.jpg
    for example with the animator controller I can run a state check on a particular animation clip.
    Code (CSharp):
    1. if(_anim.GetCurrentAnimatorStateInfo(0).IsTag("run"))
    2. {
    3. //do something
    4. }
    5.  





    #2 There doesn't seem to be a way to drag the animation track into the inspector. I couldn't find the animation track in the project folder either. Is this a bug? :eek:

    And the track names seem to change from "Animation Track" to the actual game object names depending on what you click in the project folder \ inspector.
    screenshot.8.jpg
    screenshot.9.jpg


    Thanks for the help
     
    Last edited: Jan 15, 2020
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    If I understand correctly, this is achievable with signals. Here's the layout.

    1. There's a signal emitter on the last key frame, that is attached to a signal asset (right most inspector)
    2. The Signal Receiver on the animated object (i.e. the Cube, in the left most inspector) is set up to call 'OnLastKeyFrame()' on the script - just a simple monobehaviour - attached to it.

    upload_2020-1-16_7-53-43.png



    It's by design. The tracks themselves are assets in the same file as the timeline, similar to the recorded animation clips. The subassets are hidden by default, but you can change that by removing HideInHierarchy flag from TrackAsset.hideFlags.

    Timeline is an asset that can be played with different bindings. If the editor is only looking at the timeline asset, you will see the track names. If it is editing in context, i.e. it knows who (a playable director) is playing it, then it will show which gameObjects are bound to which tracks.
     
  3. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    609


    Hi @seant_unity Thanks for your advice. I can't seem to find that method call. I can just see OnNotify();

    screenshot.5.jpg

    It seems like it's not possible to create a C# method for a Marker\Signal right? We're only allowed to use the "Signal | Reaction" tool if I understand it correctly. :oops:
    screenshot.6.jpg
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    The signal receiver is simply a convenience.

    Any Monobehaviour that implements INotificationReceiver, will get called when timeline triggers the event if it is attached to the object bound to the track.

    SignalReceiver is simply a helper that redirects that received call to a UnityEvent.

    With Signals, it's the bound object that runs something, not the signal itself. That's the default that was shipped with timeline because it general purpose, but other style of events are possible.
     
  5. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    609
    Thanks for the quick response @seant_unity

    Is it possible to expose or catch the UnityEvent via code at runtime? Rather than depending on the SignalReceiver?

    Also could you please explain how best to use\ implement INotificationReceiver? I tried below, but not getting good results. :oops: .. I read up on previous posts about Timeline\ Playable, but still had a hard time grasping how best to use INotificationReceiver with C#.
    screenshot.13.jpg


    Update*
    Is there a way to select\adjust the keyframes inside the timeline? Or is the only way through the Animation tab.:(
    screenshot.20.jpg

    Thanks again
     
    Last edited: Jan 16, 2020