Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Parenting/Unparenting in Timeline

Discussion in 'Timeline' started by angusmf, Sep 6, 2018.

  1. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    255
    Changing transform parents for animated objects in timeline has been a nightmare for me. I thought it would be an easy way to have multiple objects move together, and it is, but coupling/decoupling on the fly breaks things in ways that I can't wrap my mind around.

    Essentially, there's a MonoBehaviour with OnEnable and OnDisable defined and public references to the relevant transforms. I generally wind up with a bizarre offset applied to the objects when the object is parented or de-parented. Changing/removing/ignoring the clip offsets at best will fix the problem only on one side of the activation. Then something that was seemingly working will break once I add/change animation. Also, while it was working for me initially, now any attempts I make to change the position of the objects in script seem to be ignored. The transforms sometimes also show apparently incorrect values for scale in the debugger. Worse is that scrubbing, playing the timeline in the editor, and pressing play usually all do different things. The interplay with Timeline, Animator and my scripting seems much more complex than it looks on the surface, and days of hacking, reading and testing are not getting me closer to understanding it.

    I want to blame Timeline itself, and it is kind of a piece of junk right now. But other folks seem able to make it work, like this guy:
    https://forum.unity.com/threads/update-order-problems.515444/#post-3382166

    I'm punting on this now and will try having multiple copies of these objects already positioned and parented or not, as needed, and activate/deactivate them in the timeline. Does anyone have a recipe for doing this in a more sane way? Or some insights into general problems when working with Timeline? Thanks!
     
  2. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    255
    I did finally make some sense of this after taking a breather. Any animation I recorded was an offset to the transform's local position. Once the parent changed, any frames after that were relative to the new parent. Solutions include switching to a different clip recorded while parented, or simply recording two keyframes before and on the transition with the correct position in each.

    A big part of my confusion is that this is not how things appeared when scrubbing through the editor, and sometimes offsets of whole animations that were correct seemed to suddenly change. I solved that by correcting my code to revert to the correct parent relationship on disable.
     
  3. rnatranslation

    rnatranslation

    Joined:
    Sep 16, 2019
    Posts:
    1
    Having the same problems with parenting in Timeline :( I'm using animation tracks with signal events to detach and reparent. But as soon the object is parented (The M), it changes position, super not great!

    You said you recored two keyframes before and on the transition with the correct position in each? How did you do this? If I try to animate the position of the M on the newly parented object, this isn't an option?


    Screen Shot 2019-11-07 at 1.29.42 PM.png Screen Shot 2019-11-07 at 1.30.16 PM.png Screen Shot 2019-11-07 at 1.30.32 PM.png
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,035
    Yes - Timeline (and anything else that plays animation) only ever changes the local position and rotation. Writing to the global position and rotation is a perfectly reasonable option as well, we just haven't implemented that option.
     
    angusmf likes this.