Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug GetLocalScale issue

Discussion in 'Animation Rigging' started by SuppleTeets, Jul 2, 2022.

  1. SuppleTeets

    SuppleTeets

    Joined:
    Aug 22, 2014
    Posts:
    30
    In the Multi Parent Constraint the offsets stored for "Maintain Position" do not respect runtime scaling (it would be extremely helpful if it did btw) so I am writing my own simple parent constraint to get around that.

    In this constraint I'm mimicking lossy scale(which again, would be great to have that in jobs) by getting the scale of the hierarchy above the constrained transform and I ran into some weirdness. After some debugging I found that ReadOnlyTransformHandle.GetLocalScale() is not behaving the same way that it does in UnityEngine.Transform.localScale on the transform that has an Animator attached to it. In jobs that Transform gives you a lossy scale, whereas in UnityEngine.Transform it gives you local scale.

    Here's a simple repo in which I'm logging the local scale of a hierarchy to the console at runtime with both regular monobehavior(top) animation rigging jobs(bottom)

    Is this a bug or expected behavior?

    Here is a package with these assets:
    https://drive.google.com/file/d/1I-uEJi-7s6vgolG0xYO8rP2pMJVwIFGj/

    Thanks
     
    Last edited: Sep 19, 2022
  2. SuppleTeets

    SuppleTeets

    Joined:
    Aug 22, 2014
    Posts:
    30
    This really feels like a bug to me but for anyone with this problem of offsets not scaling at runtime a simpler way around it than writing your own constraint is to create your own offset setup that respects runtime scale like this:
    1. Turn off Maintain Offset
    2. Create a GameObject with a RigTransform component and parent it to the Source transform
    3. Move/Rotate it to the Constrained transform
    4. Create an OverrideTransform component going from new GameObject to Constrained transform
     
  3. SuppleTeets

    SuppleTeets

    Joined:
    Aug 22, 2014
    Posts:
    30
    I have since learned from looking at one of the built-in constraints that you can pass data (such as lossyScale) via the job binder's Update loop using AnimationJobCacheBuilder(). This gets me exactly what I needed.