Search Unity

Question How to change the transform of a constraint data at runtime?

Discussion in 'Animation Rigging' started by Garrafote, Jun 19, 2020.

  1. Garrafote

    Garrafote

    Joined:
    Jun 13, 2013
    Posts:
    48
    I was trying to setup a two bone IK and noticed that if I swap a transform of a constraint data at runtime the change wont make effect unless I rebuild the rig graph.

    I'm a bit lost on what is the best practice here so what I ended up doing is add a new ParentConstraint to my ik target and change the sources of this parent transform at runtime.

    upload_2020-6-19_12-9-8.png

    What are the implications of rebuilding the graph? It looks a little overkill to rebuild the entire graph in order to change a single binding. Is there a way to just rebind a transform without having to rebuild everything?
     
    Last edited: Jun 24, 2020
  2. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    Hi,

    So, as you've deduced, Transforms in constraint components cannot be changed at runtime, and instead are used as bindings in the PlayableGraph for Animation Rigging.

    You can certainly use ParentConstraint to do that, but you must know that it's not evaluated as a constraint in Animation Rigging. Instead, this is a core Unity constraint and it evaluates after Animation Rigging. Therefore, if you intend for this parent transform to move, it'll do so with one frame delay.

    Alternatively, you can use the MultiParentConstraint (which is part of Animation Rigging), and set a predefined array of parent transforms. You can dynamically change the weights in that constraint to set the active parent and have a similar behaviour.

    Otherwise, there is no way to rebind a single Transform, and while you may want to rebuild the Animation Rigging graph, this is not something you want to do all the time.
     
    Garrafote likes this.