Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Resolved Custom motion transfer constraint

Discussion in 'Animation Rigging' started by MariusLangeland, Apr 5, 2021.

  1. MariusLangeland


    Sep 5, 2018
    How do you go about enabling bi-directional motion transfer for a custom constraint?
  2. simonbz


    Unity Technologies

    Sep 28, 2015
    Hi, Adding bi-directional motion transfer for your custom constraints will requires a bit of manual labor. As specified in the documentation, not all constraints implement both "transfer to skeleton" and "transfer to constraint", and enabling the latter requires implementing an inverse constraint to "undo" the constraint effect.

    I recommend having a look at an existing constraint to grasp the workflow. The TwoBoneIKConstraint would be a very good example. Have a look at `TwoBoneIKConstraintEditor.cs` to see how we hook the constraint with the baking api and `TwoBoneIKInverseConstraint.cs` + `TwoBoneIKInverseConstraintJob.cs` to see how the inverse constraint is implemented.

    To hook up your constraint, you need to create a BakeParameters class for your constraint (link) a bit like so:

    Code (CSharp):
    1. [BakeParameters(typeof(MyCustomConstraint))]
    2. class MyCustomConstraintBakeParameters : BakeParameters<MyCustomConstraint>
    3. {
    4.   public override bool canBakeToSkeleton => true;
    5.   public override bool canBakeToConstraint => true; // Only enable this if your constraint is inversable.
    7.   public override IEnumerable<EditorCurveBinding> GetSourceCurveBindings(RigBuilder rigBuilder, MyCustomConstraint constraint)
    8.   {
    9.     // Return the list of bindings driving your constraint evaluation
    10.   }
    12.    public override IEnumerable<EditorCurveBinding> GetConstrainedCurveBindings(RigBuilder rigBuilder, MyCustomConstraint constraint)
    13.   {
    14.     // Return the list of bindings driven by your constraint.
    15.   }
    16. }