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

Constraints - Animation feature - Feedback

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

  1. ventrap

    ventrap

    Unity Technologies

    Joined:
    May 30, 2017
    Posts:
    10
    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, Grizmu, mcmorry and 5 others like this.
  2. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    1,104
    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:
    60
    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:
    1,104
    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:
    13
    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:
    29
    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:
    10
    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:
    10
    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:
    60

    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:
    1,104
    Please support Blender also, in the production release. :)
     
    ModLunar, dadude123 and recursive like this.
  11. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    1,104
    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:
    669
    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:
    1,104
    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:
    29
    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:
    1,104
    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:
    426
    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:
    29
    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:
    1,104
    I had occasion to re-visit this thread, and the significance of this really sank in the second time I read your post. :)
     
  21. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    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. MadeFromPolygons

    MadeFromPolygons

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

    bogdancoder

    Unity Technologies

    Joined:
    Feb 6, 2017
    Posts:
    29
    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:
    789
    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. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    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. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    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:
    6
    @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:
    6
    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:
    58
    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:
    755
    @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:
    29
    @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:
    755
    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:
    60
    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:
    2,068
    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. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    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:
    60
    MadeFromPolygons likes this.
  39. Grimreaper358

    Grimreaper358

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

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    289
    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:
    289
    @ventrap can you please look at above issue?
     
  42. Gokcan

    Gokcan

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

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    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:
    789
    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:
    860
    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:
    128
    @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:
    55
    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:
    201
    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:
    118
    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.
     
  50. WaqasGameDev

    WaqasGameDev

    Joined:
    Apr 17, 2020
    Posts:
    118
    I also had to struggle so I am trying to put more steps to add source dynamically.

    You will have to initiate a ConstraintSource object as I have done below

    Code (CSharp):
    1. ConstraintSource tempSource = new ConstraintSource();
    Then you will have to assign your SOURCE OBJECT TRANSFORM to this tempSource object as I have done below

    Code (CSharp):
    1. tempSource.sourceTransform = yourSourceObject.transform;
    Now your source object (which is a Unity GameObject Type) has been stored in a Constraint Source Type object. And now you can assign this tempSource object to your newly added constraint object as below

    Code (CSharp):
    1. someObject.GetComponent<ParentConstraint>().AddSource(tempSource);