Search Unity

Would it be possible to set custom values for keyframes in game with Timeline?

Discussion in 'Timeline' started by StaffanEk, Apr 24, 2018.

  1. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    Hello,

    I have a fairly trivial need, which I assume Unity has closed off from users like is customary. I want to have a script that has references to each key in my track. Depending on what happens in the game i want to change the values of my keyframes.

    For instance, a plane goes to an airfield that might have been moved by the player. As soon as the airfield has moved the position of the keyframe would be updated to the new position.

    If this isn't possible could someone from Unity tell me how to animate a cursor in the UI depending on the current resolution and aspect ratio?
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Timeline uses animation clips for all it's animations. And animation clips, at present, are not editable during runtime (i.e. in the player). So adding and removing keyframes on the built-in tracks is not really possible at the moment.

    However, a workaround to this is to use a custom track/clip and track that updates a value on a component based on an AnimationCurve. The curve would be editable in a player.

    If that seems like it might suit the problem, there are some examples in the Default Playables asset store package (TransformTween comes to mind) that might be a good jumping off point. Or post here and we will try to help.

    As for the cursor/UI/animation question, I think the answer would depend on how you setup the UI for different resolutions.
     
  3. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    I just wrote a custom dynamic position track that interpolates the current time linearly per clip. This would be a great feature to timeline. Clearly some caveats would come up by using such dynamic clips, but it would be very useful if it was possible "out of the box".