Search Unity

RotationConstraints in AssetBundles behaving strangely Unity 2018.4.14f1

Discussion in 'Asset Bundles' started by FU_JPS, Jan 17, 2020.

  1. FU_JPS

    FU_JPS

    Joined:
    Nov 21, 2012
    Posts:
    12
    Hi,

    I wasn't sure if I should post this in the Animation forum since it has to do with constraints, or if I should report it as a bug, but I would greatly appreciate if someone at Unity could look into this!

    I am currently working in Unity 2018.4.14f1 (LTS) and noticing strange behavior with RotationConstraints attached to GameObjects in characters loaded from AssetBundles as opposed to loading them with Resources.Load or dragging the prefab into the scene in the editor. This behavior happens both in the editor and in builds for Windows, iOS, and Android.

    Specifically, I have a character with secondary bones in the forearms, etc. for controlling twist. These secondary bones are controlled with RotationConstraints which are initially setup in Maya as OrientConstraints. The character is imported as an FBX and then saved as a prefab. For reasons specific to our project we are using the Generic rig instead of Humanoid. When placing this prefab in the scene or loading it via Resources.Load the constraints behave normally with no problems.

    However, when building the same prefab into an AssetBundle (using BuildPipeline.BuildAssetBundles) and then loading that at runtime (using AssetBundle.LoadFromFile, etc.) and instantiating the character into the scene the constraints immediately start misbehaving causing the constrained bones to flip wildly. This occurs in an otherwise empty scene whether the character is in its default an A-pose or if I play an animation on it.

    Not sure if it matters, but many of these RotationConstraints freeze the X-axis (X is checked for "Freeze Rotation Axes").

    My theory is that something isn't serializing correctly (loss of float precision due to compression or similar?) when loading from asset bundles. Is there someone at Unity who can look into this? We are coming up against a deadline soon and this is almost a showstopper for us. I am considering rolling my own limited rotation constraint solution to handle our situation if necessary, but we would like to use Unity's built-in constraints if possible.

    I also understand there are discrepancies between with axis orientation and order with rotations between Maya and Unity and that euler angles can be unreliable in these situations (different values in the inspector can result in the same orientation in the scene, what's shown in the inspector may be different from values in script, internal use of quaternions, etc.).

    A few peculiarities I've noticed:
    • The RotationConstraints on the original prefab were all locked with Rotation At Rest and Rotation Offset set to 0, 0, 0. The local rotation for their transforms were also at 0, 0, 0. However, when loading from the prefab, the Rotation At Rest value is slightly different - there is a very small nonzero value in Z, and X and Y are both set to 180, for example.
    • The "Lock" check is no longer set in the inspector on the constraints from the asset bundle, even though the documentation ( https://docs.unity3d.com/2018.4/Doc...nce/Animations.RotationConstraint-locked.html ) states that "in Play mode, the constraint is always locked".
    • It seems like the rotations of the gameObjects in general are slightly different from what they should be when loading from asset bundles, even if I remove the constraints from the prefab. For example the original 0, 0, 0 might be the same (180, 180, some small number) as above. Again, float precision errors?
    Update: I have added a sample project that demonstrates the problem.

    1. From the main menu, execute TestProject>Create AssetBundles to open the Create AssetBundles window.

    2. Make sure the paths and build target are correct (the defaults should be good, but just in case - the prefab path should be Assets/Prefabs/TestThing.prefab) and click the "Build Asset Bundle" button to build the bundle.

    3. Open Scenes/SampleScene.unity and hit the play button.

    4. Make sure the asset bundle path and the prefab name are correct and hit Load to load the asset bundle and instantiate its prefab.

    5. Observe that ReferenceThing's "Constrained" child and the newly instantiated asset bundle prefab's "Constrained" child have different rotation and constraint setting values. The tilted capsule "Pointer" is likely to jump back and forth to either side each frame as its parent's rotation jumps around. You may need to replay the scene a few times and/or restart Unity as the behavior appears to be random.

    Thanks in advance.
     

    Attached Files:

    Last edited: Jan 17, 2020
  2. FU_JPS

    FU_JPS

    Joined:
    Nov 21, 2012
    Posts:
    12
    Not sure if anyone is having the same problem, but we just went ahead and built our own simple constraint system (we only need aim and rotation right now).