Search Unity

Constraints - Animation feature - Feedback

Discussion in 'Editor Workflows' started by ventrap, Sep 26, 2017.

  1. ventrap

    ventrap

    Unity Technologies

    Joined:
    May 30, 2017
    Posts:
    4
    Hi all,


    We'd like your feedback on a new Animation feature that adds constraints to Unity. Following are 3 videos showcasing the feature:

    Video showing a use of animating parameters on Constraints


    Video showing the "Zero" workflow (snapping of the source to the target)


    Video showing the "Activate" workflow (preserving the offset between the source and the target)



    This feature adds support for importing constraints from Maya and Motionbuilder via FBX, as well as the ability to create constraints directly inside the Unity Editor. Position, rotation and scale constraints are currently available, unlocking new animation and rigging possibilities right from Unity without requiring custom MonoBehaviours. Aim and parent constraints are planned, but not yet implemented.


    To accelerate workflow, two action buttons can be used anytime:

    • The Activate button activates a constraint while maintaining the relative offset of the transformation of the target from the source(s). (automatically populating the offset parameters with the appropriate values)

    • The Zero button will snap the target object transformation to the source(s). (effectively putting “0” in offset parameters)

    You can download an experimental build to try it yourself:


    Mac Version:
    Constraints_ExperimentalBuild_Mac.tar.gz Download

    Windows Version:
    Constraints_ExperimentalBuild_Win.zip Download


    Please let us know what you think!
     
    mahdi_jeddi, Griz, mcmorry and 5 others like this.
  2. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    976
    This looks really useful. One point of confusion for me, after watching the videos, is how the constraints work with respect to vertices that are not the origin point of the constrained object. For example, the shock staff is constrained at its base on the ground, but the point of attachment to the character's hand is (presumably???) the object's origin point, else a lot of character controller things would be difficult to manage. Or am I misunderstanding? (Perhaps I'm confused because in the videos the hierarchy of the scene is mostly collapsed, so I can't see the relationships of objects.)

    Anyway, thanks for the work on this! Unity just keeps getting better.
     
  3. theazz

    theazz

    Joined:
    Oct 20, 2013
    Posts:
    47
    I'm an animator and I've not had this my entire career so my brain is just wired to do things how I always have, what possibilities and benefits does this open up? Any real world examples?
     
    dadude123 likes this.
  4. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    976
    I can think of a couple of things offhand:
    • For those of us who are programmers and not animators, this opens the potential of simulating animation-like behavior on an object that is attached by constraint to another object, where the "other object" is being moved by a script. This is similar to what can be done with joints on Rigidbody objects, but omits some of the baggage and unpredictability of physics modeling.
    • It could be useful for attaching non-animated objects in a constrained-but-dynamic way to a bone of an animated object (e.g., a weapon in a character's hand) without impacting the animated object's behavior.
    • I need to understand it better, but I think this might have some useful properties for managing animated characters being attached temporarily to moving platforms, or swinging from cables or bars, etc.
     
    theazz likes this.
  5. chlagou

    chlagou

    Joined:
    Jan 15, 2014
    Posts:
    9
    Nice addition! keep the good work folks.
    if you can add a custom link between different transform ( move to scale, rotation to a move,...) it will be perfect.
    one question if 3dsmax constraint will be supported through fbx import ?
     
  6. bogdancoder

    bogdancoder

    Unity Technologies

    Joined:
    Feb 6, 2017
    Posts:
    11
    We support importing constraints from FBX files. Our compatibility targets are Maya and MotionBuilder.
     
    laurentlavigne likes this.
  7. jnseb

    jnseb

    Unity Technologies

    Joined:
    Oct 3, 2016
    Posts:
    4
    Hello Syscrusher,

    Your observations are accurate. The reason we need to use GO (Zero & Activate) has "alternative pivots" in this video is simply because of the type of constraint we support in our first implementation. The current Constraint_Experimental_Build version only contains simple constraints (Position, Rotation, and Scale). Therefore, in this example video, we need to use a GO (Zero & Activate) to compensate for the absence of a true Parent-Child constraints... which should definitively come next in our deployment strategy.

    As always, thank you for your feedbacks

    JnSeb
     
    syscrusher likes this.
  8. jnseb

    jnseb

    Unity Technologies

    Joined:
    Oct 3, 2016
    Posts:
    4
    I can surely think about a lot of possibility and workflows that this new feature will open for animators...

    Props management by a character is definitively one of the premiere use cases.

    For example, you want the sword of your character to be attached to is back and then to be attached to is hand. You can simply add 2 GO (one child of the Spine bone and the other one child of the Right-Hand bone) that both refer to each sword positions (Source). Then you should add 2 constraint component to the target object (in this case the Sword). Each constraint would use a different source (Back position and Right-Hand Position)
    Since most of the constraints parameters are animate-able you can cross animate the Weight of each constraint in order to turn on and off each constraint as wanted in order to have only one source influencing the position of the sword.

    Again, having the possibility to animate the activation (Weight parameter) of each constraint is really where most of the power of the feature stand...

    JnSeb
     
    syscrusher likes this.
  9. theazz

    theazz

    Joined:
    Oct 20, 2013
    Posts:
    47

    I see, thanks for the response, In the past we would do this offline in assets and attach the sword to an extra node /bone for this. It'll certainly be interesting to see how these features change the workflows!

    Thanks
     
  10. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    976
    Please support Blender also, in the production release. :)
     
    ModLunar, dadude123 and recursive like this.
  11. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    976
    That's a really interesting point that I hadn't considered. Not just the weight, but also that the other parameters are animatable. I'm a programmer, not an artist, so I of course immediately thought of them being controlled by C# script, but one could also do some really interesting things with timelines controlling the parameters. That could be useful for moving environment pieces, like swinging vines that entangle a character,, or a carryable lantern with a swinging handle.
     
  12. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    604
    I'll second this, at least on final release. A lot of indie studios use blender instead of Maya/Max due to cost.
     
    ModLunar and dadude123 like this.
  13. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    976
    Interestingly, my company has two seats of Max. A colleague is using one, and the other was offered to me. I tried it and didn't like it as well as Blender. It's really bloated, in my opinion, and the license management installation is really intrusive. Blender does everything I need and more.
     
    ModLunar likes this.
  14. bogdancoder

    bogdancoder

    Unity Technologies

    Joined:
    Feb 6, 2017
    Posts:
    11
    It is not a question of us not wanting to support max or blender. Our support is limited by those programs' ability to export constraints to FBX.
     
  15. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    976
    I didn't realize that Blender's FBX exporter doesn't support constraints. Thanks for enlightening me.
     
  16. dizzymediainc

    dizzymediainc

    Joined:
    Apr 6, 2014
    Posts:
    102
    I NEED THIS!! I have been having a hard time with getting nice and fluid movement of gameobjects that are attached to the character body (weapons, accessories, etc.) and this seems like it will really solve that issue :) when can we expect it to hit the store?

    What would be the minimum unity version to use this? I generally create my projects in 5.6 for now while they work out all the bugs and issues with 2017 versions. Would be great if this wasn't locked down to the 2017 versions :D
     
  17. bogdancoder

    bogdancoder

    Unity Technologies

    Joined:
    Feb 6, 2017
    Posts:
    11
    The constraints will be released in 2018.1.

    We will support Position, Rotation, Scale, Aim and Parent constraints and you will be able to import them from FBX files, as well as create and animate them in Unity.

    By all means, try them out when the beta for version 2018.1 comes out - any feedback is much appreciated.
     
    laurentlavigne and syscrusher like this.
  18. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    At first I didn't get what was the point of this, but the example with the sword being attached to the back of a character makes sense.

    Just so I get this right, normally we'd just interpolate the position of the sword towards the "carry" position with a script, but now this can be done entirely with the animation/timeline window?

    That one example makes sense, but if anyone can think of more scenarios that would be awesome. (I'm a programmer and don't really have much to do with animation, so maybe that's why I'm having a hard time getting this :p).

    Edit:
    So constraints can be used to fix the old workflow: I want to give a sword to a character, but for that I'd have to set the sword GO as a child of the hand-bone of the character.
    So if the character gets destroyed, the sword will get deleted along with it. Most of the time we'd want that, but sometimes we want to attach things without getting them deleted.
    Is that right?

    And it will also allow us to blend objects to different points/objects, right?
     
    Last edited: Dec 10, 2017
  19. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Is this already implemented in the recently released beta?
     
  20. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    976
    I had occasion to re-visit this thread, and the significance of this really sank in the second time I read your post. :)
     
  21. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,997
    Does this mean we can import and use IK from maya?
     
  22. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    What does this have to do with ik? (sorry I'm mainly a programmer and I'm not really familiar with the modeling work flow haha)

    Can Maya precompute IK movement for every possible angle + distance combination? Is that even possible? (and feasible)

    I thought this was just about being able to lock game objects in some location/rotation relative to something else?
     
  23. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,997
    As in, IK constraints?
     
    Last edited: Jan 15, 2018
  24. bogdancoder

    bogdancoder

    Unity Technologies

    Joined:
    Feb 6, 2017
    Posts:
    11
    IK contraints are not supported at the moment.

    The supported constraint types are position, rotation, scale, aim and parent.

    They are already available in 2018.1 beta.
     
    dadude123 likes this.
  25. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    562
    Will a variation of this be added to Mecanim as a socket system? I imagine it would be useful to be used like that in addition to how it works right now.
     
  26. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,997
    Sounds like one day IK may be? Im not trying to hold you to anything dont worry, but do think about it as its a game changer for an engine to have this built in!
     
  27. nosakay

    nosakay

    Joined:
    Nov 7, 2016
    Posts:
    1
    Is this function related to "Freeform Animation: Modular Rigging" in the roadmap?
     
    awesomedata likes this.
  28. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,997
    Any more info on this or on modular rigging? is parent constraints available yet for import? or creation?
     
  29. kobechenyang

    kobechenyang

    Joined:
    Jan 16, 2013
    Posts:
    2
    @bogdancoder How do you add a ConstraintSource from code? I tried to convert Transform into ConstraintSource without success.
     
  30. kobechenyang

    kobechenyang

    Joined:
    Jan 16, 2013
    Posts:
    2
    ok. Figured it out in case someone need this.
    new ConstraintSource(){sourceTransform = mTransform}
     
    juan-jo likes this.
  31. Arcan-Studios

    Arcan-Studios

    Joined:
    Mar 12, 2015
    Posts:
    49
    work well with one parent constraint object, but if i want to use two parent i cant going to work well, because, the offset change for the two parent, its complety useless with two parent, we need, mark the offset of the parent individually, i think i dont explain well. i want to change object parent with two parent, so i move in the animation time, and mark activate to record the offset for the parent, the problem its then change the offset in the other parent.
     
  32. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    715
    @ventrap @bogdancoder Hi guys, I have a quick question regarding constraints used for character props. What would be most performance-friendly option: reparenting props transforms to the character joints or using constraints instead?

    In other words, what's faster: having transforms reparented under a hierarchy or evaluating constraints linked to that same hierarchy?
     
  33. bogdancoder

    bogdancoder

    Unity Technologies

    Joined:
    Feb 6, 2017
    Posts:
    11
    @Seith I think you should try it out and profile. The transform hierarchy has been heavily optimized and using the animation constraints does introduce some overhead. However, if the hierarchy is complicated, it may pay off to use the animation constraints.

    Besides, the constraints system allows you to solve for other use cases, like dynamically picking up objects and blending between the parented and unparented states.
     
    awesomedata likes this.
  34. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    715
    Thanks very much for you reply! :)

    So I did some stress tests and the results are quite clear. Base line is just the character. Test 1 involved parenting 100 spheres to each joint (except the fingers) on a humanoid avatar for a total of 2.3k spheres. Then starting over but this time constraining 100 spheres. Test 2 was the same as test 1, only this time using 100 empty transforms instead of spheres.

    Base line: 130fps

    Test 1:
    Parenting (spheres): 70fps
    Constraints (spheres): 9fps

    Test 2:
    Parenting (empty transforms): 125fps
    Constraints (empty transforms): 9fps

    I think the results speak for themselves. As much as I really like the constraints principle and implementation, they seem to be no match for a simple reparenting. As you said though, they can be great in some specific situations. I will definitely revisit them later on!

    Update:
    So I did some more tests and here are the results:

    Parenting: 70fps
    Constraints: 9fps
    Match pos/rot/scale (no offsets): 60fps
    Match pos/rot/scale (offsets by multiplying right, up, forward): 54fps
    Match pos/rot/scale (offsets by using TransformVector): 57fps
    Match pos/rot/scale (offsets using vector3 float decomposition): 59fps
    Match pos/rot/scale (offsets using vector3 float decomposition every other frame): 70fps

    As the last result clearly shows, matching transforms in an Update loop allows many optimization tricks. Like updating only if the actor is seen, or depending on the actor's speed, or its distance to the camera, etc...
     
    Last edited: Sep 28, 2018
  35. theazz

    theazz

    Joined:
    Oct 20, 2013
    Posts:
    47
    Great work as usual Seith!

    Dunno if this is possible but when we lower the weight it'd be useful if the goal object retained it's transformed from it's own animation.
     
    Seith likes this.
  36. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    89
    Hello,
    The important question is, when are the transforms updated, is it working like parenting.
    Changing some of ancestors (parents) transform will result in immediate change in constrained transforms.
     
  37. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,997
    Seeing as I got no reply for a year, Ill ask again:


    Any info on modular rigging? Its been on the road map for a while and according to roadmap goes into 2019.1
     
    awesomedata likes this.
  38. theazz

    theazz

    Joined:
    Oct 20, 2013
    Posts:
    47
    GameDevCouple_I likes this.
  39. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    562
    It's been available in the Package Manager for 2019.1 for a few months now.
    It's called Animation Rigging.
     
    GameDevCouple_I likes this.
  40. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    200
    Hi All
    @bogdancoder Constraints does not work when I reverse animation using box tool. Is there a fix about it? Before reversing all working good.@ventrap
     
  41. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    200
    @ventrap can you please look at above issue?
     
  42. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    200
    @bogdancoder I cannot animate constraint features in timeline as well!!!
     
  43. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,997
    Dude, dont do 3 posts one after the other just edit your post, its close to spamming otherwise.

    Brilliant, does this mean we can rig and share parts of rigs between things? Such as rigging a character and taking the legs part and reusing it in another rig? Or have I completely misunderstood what modular rigging is?

    Also does this allow for actual rigging, or is it just adding IK onto an already created rig? Essentially do I need to still rig stuff in DCC app first to use this?
     
  44. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    562
    From what I'm seeing you should be able to transfer what you rig to another character since it's just game objects with scripts linking them to other objects. If you make it a prefab and instance it and change whats needed it would probably work how you want it to.

    You will have to use a DDC app to do the rigging and skinning. This is just to ease up most of the work afterward with animations or creating certain gameplay elements.

    They did a talk at GDC that went over a few different ways you can use it to aid animations and gameplay as well as the samples included.

    Can't directly link the talk so you will have to scroll down and look for
    Introducing the New Animation Rigging Features - https://www.gdcvault.com/browse/gdc-19
     
  45. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    726
    Hello folks!

    I created this script to test this feature from code and this script doesn't work! Anyone here knows why wouldn't this work?

    I have an sphere with this script and the position constraint on it, when I check the isConstrained in the inspector I see the target have been added to the position constraint component, it has been activated, the weight is 1 and it is locked but the sphere doesn't follow the target...

    Script:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Animations;
    3.  
    4. public class ConstraintScript : MonoBehaviour
    5. {
    6.     PositionConstraint posCons;
    7.     public bool isConstrained = false;
    8.     ConstraintSource target;
    9.  
    10.     private void Start()
    11.     {
    12.         posCons = GetComponent<PositionConstraint>();
    13.         target.sourceTransform = GameObject.FindWithTag("TagShark").GetComponent<Transform>();
    14.     }
    15.  
    16.     private void Update()
    17.     {
    18.         if (isConstrained)
    19.         {
    20.             if (posCons.sourceCount < 1)
    21.             {
    22.                 posCons.AddSource(target);
    23.                 posCons.weight = 1.0f;
    24.                 posCons.constraintActive = true;
    25.                 posCons.locked = true;
    26.             }
    27.         }
    28.     }
    29. }
    Regards,
    Carlos
     
  46. PandaArcade

    PandaArcade

    Joined:
    Jan 2, 2017
    Posts:
    25
    @ventrap any word on performance improvements for the constraint system?

    In testing done by @Seith it's shown to be disappointingly slow. We also found this in our project. We compared our own solution to the constraint system, the constraint system was 8 times slower.
     
    Seith and Lahcene like this.
  47. Lahcene

    Lahcene

    Joined:
    Jun 18, 2013
    Posts:
    22
    I was very excited about the new package, until I read about its performance,
    doesn't it take advantage of the job system? Why is it so slow?
     
    PandaArcade likes this.
  48. iSinner

    iSinner

    Joined:
    Dec 5, 2013
    Posts:
    133
    This is similar to some of the Animation Rigging constraints, are these components related in any way to animation rigging components?
     
  49. Hellwaiker

    Hellwaiker

    Joined:
    Jan 8, 2016
    Posts:
    73
    Hey, How can I simulate the inspector "Activate" button click from code?
    I want to use ParentConstraint and activate it at specific point in the game via a script so Current offsets between Object and Source are used to update offset variables.