Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question How to update child objects inside custom constraint?

Discussion in 'Animation Rigging' started by hawaiian_lasagne, Jan 19, 2021.

  1. hawaiian_lasagne

    hawaiian_lasagne

    Joined:
    May 15, 2013
    Posts:
    128
    Is it possible to update child objects inside a custom constraint? I'm using a multi parent constraint to attach a weapon to a characters hand, and then a custom aim constraint to aim a child raycast object inside the weapon at a given target by rotating the spine.

    The problem is when I rotate the spine in the custom constraint the weapon transform does not update, because technically it's not parented to the spine, other than by the multi-parent constraint.

    I was thinking if I could force update the children inside the constraint that might fix it but I'm not sure if this is the correct approach

    Thanks in advance!
     
  2. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    When you say you're rotating the spine, do you mean during playmode, or at edition?
    For constraints to be evaluated, and for your targeted transform to update, you need to either go in playmode, or keyframe your animated hierarchy in the Animation Window or Timeline.
     
  3. hawaiian_lasagne

    hawaiian_lasagne

    Joined:
    May 15, 2013
    Posts:
    128
    The spine bones are being rotated inside my CustomRig constraint, 'WeaponIK'.

    My Constraints are evaluated in this order:

    Rig:
    Multi-Aim (Attaches weapon to hand)
    WeaponIK (Aims weapon tip at target, by rotating the spine)

    The WeaponIk constraint is rotating a the spine bones to aim an effector (weaponAim) at a target. The effector is a child object of the weapon. The weapon however, is attached to the hand via a multi parent constraint, which is evaluated before the WeaponIK constraint.

    The problem is, when the WeaponIK constraint is run, I am updating the spine bones to aim at the target, but the weapon is not updated. It stays hanging where the Multi-Aim constraint attached it to the hand, before the WeaponIK constraint runs.

    Does that make sense?

    I have added the [SyncSceneToStream] to both the target and weaponAim objects in my constraint (no idea if this is right). I'm also storing them inside the job using ReadOnlyTransformHandle. Again I was a bit confused if I should use this, TransformStreamHandle, or TransformSceneHandle, as the target is outside of the player's root, but the weaponAim is inside the player root, but outside the skeleton.

    Apologies for the information overload!
     

    Attached Files:

  4. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295