Search Unity

Ways to animate picking up an object...

Discussion in 'Virtual Production' started by akent99, Sep 3, 2021.

  1. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    I had two people recently ask how to animate a character picking up an object. I shared two approaches I have used, I know also about Animation Rigging in unity, but would love to hear of better solutions to the problem... or even what you tried that did not work well!

    Approach one - two objects with different parents and using an activation track to make it *look* like object was picked up.



    Approach two - a script with lerp ing to follow other objects (eg location on table and hand).



    I am doing this with the Sequences package where I create a new set of objects per shot (usually). I am not doing this for a game where it has to flow well for a long time on the same objects.
     
    hunz likes this.
  2. hunz

    hunz

    Joined:
    Oct 16, 2012
    Posts:
    29
    Hey,

    Thanks for this!

    I use a different technique that I stumbled across for this piece I created in unity - Super Human - Parker

    There is a group of scripts in unity called "Constraints" I use these to ensure 3point lighting follow my main characters around but it's also really good for object transfers because you can animate the weight directly into the timeline or trigger it off via a script.

    So if you "add component" and type in "constraint" this will pop up

    upload_2021-9-5_15-32-9.png

    There is Parent, Position, Rotation and Scale. Hope this opens up some new ways to do things.

    (I also use animation rigging now and it makes looking at other actors super easier - I did that for this piece here - 7bit Hero)

    Thanks for sharing BTW. Very cool!
     
  3. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    I loved your animations, both of them! Super Human in particular - I have no idea how to do most of that, all the effects.

    I looked at Constraints when playing with the Animation Rigging package, but did not look that closely. I am planning to use motion capture tools like VSeeFace etc (maybe the new face camera support from Unity). If I can get the capturing workflow easy enough, I was hoping to not use as many animation clips for walking, running, etc. But we shall see.

    For head turning, I cobbled together this script from a few sources for use with VRoid Studio characters. It includes 3 targets can lerp between (so can look from character to character), plus X/Y manual offsets (just in front of face so don't have to look at another object if dont want to), plus it has a head turn strength (100% = turn head to look directly at other character, 0% head stays looking straight ahead), with a speed of head turn (so you can move eyes quickly to snap onto target, but head turns a bit slower to look.

    I find it useful for my type of sequences per shot (I do many short video clips of a few seconds, rather than long flowing video clips. Each clip has a new set of character instances, so I just turn this script on per shot when its needed and drop in the look-at-targets for that shot. So far so good, but I did find a few interesting things like trying to decide if I should limit the maximum distance a head should turn, but ended up not doing it - I can just see what it looks like and adjust the shot. That would be different in a game where it must always behave well no matter what a player does.
     
    hunz likes this.
  4. hunz

    hunz

    Joined:
    Oct 16, 2012
    Posts:
    29
    That sounds super interesting. I'll keep an eye on your youtube GL with everything DM me if you need anything as well.
     
  5. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    I was reading up more on IK and Animation Rigging packages, to enable combination of live recordings with picking up objects in a scene (or putting hand on a desk or door knob etc where you need precise positioning control). I assume you either have to live capture the exactly correct positions to line up with the real and virtual worlds, or you need to override inside Unity to make adjustments (e.g. using IK) and then blend between the recording and the IK.

    There is OnAnimateIK() where you can script up your own IK. But you have to use it with an Animator Controller and set "IK Pass" to true. See https://forum.unity.com/threads/ik-in-timeline-animations.528251/

    Using Animator Controller however appears not to work well with override tracks according to https://forum.unity.com/threads/blending-between-timeline-and-animation-controller.870553/. So you have to choose between Animation Controllers or Timelines with animation clips with overrides and Avatar Masks. Unless this has changed, they don't play well together. I use the override tracks for facial expressions and hand positions (because I don't have reliable finger tracking)... hence I don't think using an Animator Controller will work for me.

    There is the Unity Animation Rigging package that allows you, in timeline, drag the hand etc as an IK. I like this video overview
    from Unity. (Also https://forum.unity.com/threads/animation-rigging-and-timeline-quick-guide.905984/) You can use Animation Rigging in Preview mode, which sounds good for use with Sequences. You animate the weight up where the adjustment to the recorded movement is needed, then animate it down afterwards. So as long as the actor got "pretty close" to where the object is, you are set. Note: the video uses Animator Controller from what I can see.

    But Animation Rigging and Sequences has been giving me pain! E.g. https://forum.unity.com/threads/bug-possible-conflict-between-rigbuilder-and-sequences.1134019/. More example exceptions in Console:

    Code (csharp):
    1.  
    2. MissingComponentException: There is no 'PlayableDirector' attached to the "interior" game object, but a script is trying to access it.
    3. You probably need to add a PlayableDirector to the game object "interior". Or your script needs to check if the component is attached before using it.
    4. UnityEngine.Playables.PlayableDirector.get_playableAsset () (at <b063ef8cb96c4883b75f10561b7f0a02>:0)
    5. UnityEditor.Timeline.SequenceHierarchy.ValidateSubElements (System.Collections.Generic.List`1[T] subElements, UnityEngine.Playables.PlayableDirector director, System.Collections.Generic.List`1[UnityEditor.Timeline.SequenceHierarchy+SequenceBuildingBlock]& buildingBlocks) (at Library/PackageCache/com.unity.timeline@1.6.1/Editor/State/SequenceHierarchy.cs:237)
    6. UnityEditor.Timeline.SequenceHierarchy.FromSequencePath (UnityEditor.Timeline.SequencePath path, System.Boolean forceRebuild) (at Library/PackageCache/com.unity.timeline@1.6.1/Editor/State/SequenceHierarchy.cs:188)
    7. UnityEditor.Timeline.WindowState.SetCurrentSequencePath (UnityEditor.Timeline.SequencePath path, System.Boolean forceRebuild) (at Library/PackageCache/com.unity.timeline@1.6.1/Editor/State/WindowState.cs:441)
    8. UnityEditor.Timeline.TimelineWindow.RestoreLastSelection (System.Boolean forceRebuild) (at Library/PackageCache/com.unity.timeline@1.6.1/Editor/Window/TimelineWindow_Selection.cs:65)
    9. UnityEditor.Timeline.TimelineWindow.RefreshSelection (System.Boolean forceRebuild) (at Library/PackageCache/com.unity.timeline@1.6.1/Editor/Window/TimelineWindow_Selection.cs:60)
    10. UnityEditor.Timeline.TimelineWindow.OnEnable () (at Library/PackageCache/com.unity.timeline@1.6.1/Editor/Window/TimelineWindow.cs:127)
    11. UnityEditorInternal.InternalEditorUtility:LoadSerializedFileAndForget(String)
    12. UnityEditor.WindowLayout:LoadDefaultWindowPreferences()
    13.  
    and

    Code (csharp):
    1.  
    2. InvalidOperationException: Sequence contains no elements
    3. System.Linq.Enumerable.Last[TSource] (System.Collections.Generic.IEnumerable`1[T] source) (at <b024aa277ab0422080e4a1dbe1f3c835>:0)
    4. UnityEditor.Graphs.AnimatorControllerTool.UpdateStateMachineSelection () (at <ac9a6525061f4e29af6bedf66fd7c5fe>:0)
    5. UnityEditor.Graphs.AnimatorControllerTool.RebuildGraph (System.Boolean updateSelection) (at <ac9a6525061f4e29af6bedf66fd7c5fe>:0)
    6. UnityEditor.Graphs.AnimatorControllerTool.UndoRedoPerformed () (at <ac9a6525061f4e29af6bedf66fd7c5fe>:0)
    7. UnityEditor.Undo.Internal_CallUndoRedoPerformed () (at <b0d21c8593a94bc3a2b5da97f0d5796a>:0)
    8. UnityEditor.EditorApplication:Internal_CallGlobalEventHandler()
    9.  
    and

    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. UnityEngine.Animations.Rigging.RigBuilder.UpdatePreviewGraph (UnityEngine.Playables.PlayableGraph graph) (at Library/PackageCache/com.unity.animation.rigging@1.1.1/Runtime/AnimationRig/RigBuilder.cs:178)
    4. UnityEngine.Timeline.AnimationPreviewUpdateCallback.Evaluate () (at Library/PackageCache/com.unity.timeline@1.6.1/Runtime/Animation/AnimationPreviewUpdateCallback.cs:40)
    5. UnityEngine.Timeline.TimelinePlayable.Evaluate (UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData frameData) (at Library/PackageCache/com.unity.timeline@1.6.1/Runtime/TimelinePlayable.cs:288)
    6. UnityEngine.Timeline.TimelinePlayable.PrepareFrame (UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info) (at Library/PackageCache/com.unity.timeline@1.6.1/Runtime/TimelinePlayable.cs:249)
    7. UnityEngine.Timeline.DirectorControlPlayable:ProcessFrame(Playable, FrameData, Object) (at Library/PackageCache/com.unity.timeline@1.6.1/Runtime/Playables/DirectorControlPlayable.cs:123)
    8.  
    When I move the IK target, nothing happens (the arm does not bend) in Preview or Record mode.

    Further, if I create a Timeline outside of Sequences and Copy / Paste the character from the Sequence timeline into my stand-alone timeline, Rigging Animation works - I can do IK movement. So sounds like a conflict between the Sequences package and Animation Rigging causing the above stack traces, which is disabling the functionality. (Does that seem reasonable?)
     
  6. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    These look like bugs!

    Are you able to reproduce them easily? If so, can you send us bug reports using the Unity bug reporter. They seem to indicate issues in Timeline, StateMachine and Animation Rigging, but we'd need to know how we can reproduce them.

    I do not know how the Sequences package might trigger these issues, I'll let the developers working on that package answer if they have more insight on the matter.

    However, bug reports will definitely help us figure it out :)
     
  7. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Just to answer on this thread, yes - It is a sequences bug and they have created an internal ticket. There was a possible workaround of disabling preview while switching around, but i could not get it to work (yet).
     
  8. ellka

    ellka

    Unity Technologies

    Joined:
    Jun 17, 2019
    Posts:
    71
    Hey @akent99, I just spend a bit of time trying to repro what was mentioned in this post, this one is indeed logged and reproducible.

    However, while playing around, I couldn't find how to get the problems you are highlighting here or in this other post.

    It might be all related or different bugs.
    So I'll join @simonbz to ask you to report all that using the Unity bug reporter. Having a project and repro steps will be very helpful! And if you have different set of repro steps that lead to different errors, don't hesitate to log multiple bugs.

    Thank you and sorry for the inconvenience!
     
  9. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    I have created and uploaded something: "(Case 1367857) Animation Rigging throws exceptions when used with Sequences package (sometimes!)". It did not go as smoothly as I hoped, so not sure how useful it will be. The null Playable message is still true after upgrading from b5 to b12
    • I tried the original project (but it turned out to be 23GB!! So I did not upload it.)
    • I tried creating a small project with minimal files, but Animation Rigging worked perfectly even with nested sequences. After a few hours of trying things, it all worked perfectly. Not a single exception.
    • I tried doing a copy/paste of the raw files of the project so I could delete things - but the copy made it update lots of .meta files I think - everything fell apart with unknow GUID errors.
    • I finally tried export/import of a custom package, with the most success. I managed to get a project that repeated the stack trace but was much smaller than 23GB. This is what I uploaded.
    The other stack traces I have not repeated yet, but I have upgraded to b12 - so I will report again if I hit the same problems again. But I cannot repeat them reliably. The "null Playable" issue is pretty easy to repeat - and if I disable the RigBuilder component on the character the exceptions in the stack goes away.
     
  10. galicaly

    galicaly

    Joined:
    Dec 23, 2023
    Posts:
    1
    I have animation about my object but how to join it ,and how to move my object with animation.