Animate any public Variable over time?

Hi everyone,

would it possible to declare a public variable by Script and animate the value graphically over time by the new Timeline Tool?

This is an extremely useful behavior to control vars over a predefined time. Eg changing directional light or Sun color over time of day or anything.

Is it possible with the new timeline tool?

thank you

Yes; if you use an Animation Track and bind it to an object that has a component that has properties that you desire to animate over time (Such as a Light’s color or a MonoBehaviour’s public float values), then it can be done. :slight_smile:

Did you attempt this and have different results?

Only to understand correctly. :slight_smile:

If I add an component to an game-object that include eg.
public float n1;
public float n2;
then its possible to “animate” these over time via Animation Track?

The only issue with usability of the new Unity TimeLine editor that it have no any logical time zoom like Adobe AfterEffects does to manipulate larger scales. Over 24:00h.

So I wrote a tool that is able to, but I can’t access a public static var directly by pointer in Unity unfortunately.


These manipulations for a variable over a day is not possible to handle by TimeLine.

Hmm… I think the implementation of the technique is different.
In my system I can set a keyframe to any time eg 12:00h = 43200s. On run the “daytime” then Update() interpolate any variable from a start time existing to the next time set by a keyframe and so on… The interpolation quantize can be set by separate update tick eg. 20 th/sec, to run exactly in seconds.

This seems to be not possible with Timeline in this way.

As answered before, yes. :slight_smile:

Unity-Authored animations can only animate specific types of value of variable: float, int, color etc. Have you tried any of these for your setup?

Have you attempted to implement this? If yes, it would be good to share your Unity results!

Yes I tried, but I was not able to configure TL correctly.

  • Attached a simple component to GO(TimeLineVar) : public float MyTimeLineVar = 777;
  • OpenTimeLine : Created TimeLineAsset for GO(TimeLineVar) : saved
  • Added a AnimationTrack…

From this point I stuck.

Can you help here how to configurate and to open/edit the public float MyTimeLineVar in the TL graph?

If that works, it would be great to have also a Display-Time-Option, to the existing option Seconds and Frames.

For sure if you work on a larger Time base animation it become lite difficultly to know were you are. Also the “seconds and frames” should have an option to display minutes in front. you can enlarge the hight of the timeline for 5 pixel and display 600f: 5:00m on 2 rows.

Its pretty much exactly the same process as animating in the Animation Window:

  1. Click the Red Record Button on the Track Binding Column of the Object you want to animate
  2. Timeline is now recording!
  3. Move Timeline Playhead to a specific frame/second
  4. Change the value on the script
  5. Keyframe for that value should be added to that Animation Track
  6. Go back to Step 3 and repeat until satisfied
  7. Click the Red Record Button again to stop recording.
1 Like

Well first off the existing animation tools can already do this. You can animate virtually anything you can set in the inspector. One thing I’ve done before when I wanted to use animation to set something up but scripts to control how and when it moved was to manually set the animation time in a script every frame. I don’t know if this is efficient or even a good way to do it, but it worked.

Also, you can use just plain AnimationCurve objects. Just declare a public AnimationCurve object, use the curve tools to define how you want a value to change in relation to time (or any other value, really) and just use a script to evaluate the AnimationCurve and set the output. This is also something I do often. I even use AnimationCurves for things you might not consider, such as level difficulty (instead of time, use the level you’re on) and things that scale with difficulty get a multiplier from this curve and can scale themselves accordingly.

But anyway, there are many options to do what you want with the existing tools.

1 Like

I tried animate and it seems to work (sometimes).

But some editing stuff did not.

  1. It’s not possible to animate: public Color32 myChoosenColor32 = new Color32(11, 22, 33, 05);

  2. After recording the first variable, then the second, the timeline graphic windows stays at the first value range and all become strange. If the first variable value is 777 and the second 2.0. the display value range of the Graph doesn’t change. So I didn’t came in range to edit the second var and the graph stopped working.
    3064591--230333--Untitled-2.jpg

And after this point it was not possible to edit the properties via the graph editor in TL

There are a brunch of usability fails in my opinion.

  1. Hold SHIFT + should move the white Time-Position-Line and snap onto a key-frame if it’s in range of 2-3 pixels, because of start previewing anything.

  2. Editing the Graph should possible in the TL Graph at any time. Currently after recording it fails completely in my case.

  3. The pop-down menu should not appear on the Key-Frame-Bar. This is a different context.
    Here a drop down menu of [Enable Snap] [Bring into Range] [Zoom vert, horz] etc. would be nice.
    3064591--230336--Untitled-6.jpg

  4. A click into the Key-Frame-Bar should select a key-frame and it should be possible to move and snap to the displayed values and position lines above.
    3064591--230337--Untitled-3.jpg

  5. After duplicate a track, the graph seems to work again.
    3064591--230338--Untitled-4.jpg

  1. Moving a key frame hangs very every-time. Very slow move works.
    3064607--230339--Untitled-7.jpg

  2. TL fails display on setting the PlayableTimeline-Asset to 86400 seconds a day by 1 frame and moving to a higher range. For sure I can reduce to length to minutes (1440) per day, but I do not want to happen stuff base on fixed minutes only.

  3. As I told you, animate variables over a day is not recommended currently because of the missing Display > Time option and other issues.

BTW, there are other issues I was able to address…

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Timeline.AnimationTrackInspector.GetTransform () (at C:/buildslave/unity/build/Extensions/Timeline/Editor/inspectors/AnimationTrackInspector.cs:177)
UnityEditor.Timeline.AnimationTrackInspector.OnInspectorGUI () (at C:/buildslave/unity/build/Extensions/Timeline/Editor/inspectors/AnimationTrackInspector.cs:73)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1220)
UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

After closing TL. from at current state I got this.

Any comments to the issues and improvements?

I am not on the Timeline team so am not part of the development process of the feature. However, I shared this thread with them so hopefully they have put eyes on it. :slight_smile:

Does it mean, if I did not quoted your post, then all my work was a wasted and none of the TimeLine guys read anything about?

Sorry for the delay on the response…let me try to address these

  1. Right now integer (including Color32) animation isn’t supported. This is being worked on by the animation team, so when it arrives, I’d expect Timeline support shortly there after.

  2. You can reframe the graph with the A and F keys.

For the next list

  1. This is common in the feedback…something for us to look into.

  2. Will be fixed in a future beta

As for the rest, the feedback has been noted - thanks for taking the time to pass it on.