Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Animate any public Variable over time?

Discussion in 'Timeline' started by Quatum1000, Apr 10, 2017.

  1. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    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
     
  2. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,479
    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. :)

    Did you attempt this and have different results?
     
  3. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Only to understand correctly. :)

    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.

    Untitled-1.jpg
    These manipulations for a variable over a day is not possible to handle by TimeLine.
     
  4. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    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.
     
  5. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,479
    As answered before, yes. :)

    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?
     
    Last edited: May 11, 2017
  6. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,479
    Have you attempted to implement this? If yes, it would be good to share your Unity results!
     
  7. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    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.

    Untitled-1.jpg

    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.

    Untitled-3.jpg

    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.

    Untitled-2.jpg
     
    Last edited: May 8, 2017
  8. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,479
    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.
     
    Quatum1000 likes this.
  9. UziMonkey

    UziMonkey

    Joined:
    Nov 7, 2012
    Posts:
    206
    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.
     
    Quatum1000 likes this.
  10. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    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);
    Untitled-1.jpg

    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.
    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.
    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.
    Untitled-3.jpg

    5) After duplicate a track, the graph seems to work again.
    Untitled-4.jpg
     
    Last edited: May 10, 2017
  11. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    6) Moving a key frame hangs very every-time. Very slow move works.
    Untitled-7.jpg

    7) 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.
    Untitled-8.jpg

    8) 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..
     
    Last edited: May 10, 2017
  12. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEditor.Timeline.AnimationTrackInspector.GetTransform () (at C:/buildslave/unity/build/Extensions/Timeline/Editor/inspectors/AnimationTrackInspector.cs:177)
    3. UnityEditor.Timeline.AnimationTrackInspector.OnInspectorGUI () (at C:/buildslave/unity/build/Extensions/Timeline/Editor/inspectors/AnimationTrackInspector.cs:73)
    4. 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)
    5. UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
    After closing TL. from at current state I got this.
     
  13. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Any comments to the issues and improvements?
     
  14. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,479
    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. :)
     
  15. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    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?
     
  16. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    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

    4) This is common in the feedback....something for us to look into.

    6) 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.