Search Unity

[5.3.0] Animator culling: "Cull Completely" not working until GO is seen once. [Edit:Fixed in 5.4b3]

Discussion in 'Animation' started by Le-nain, Mar 16, 2016.

  1. Le-nain

    Le-nain

    Joined:
    Nov 26, 2012
    Posts:
    62
    As the title states, I just stumbled after some testing on the fact that when you animator is set to Cull Completely (though I assume it's gonna be the same for Cull Updates Transforms), this culling only starts taking place AFTER said animator has been actually inside your view frustum and then went back outside.

    I find this behaviour really weird (and kinda defeats the purpose) and I believe this isn't working as intended; one would assume that on startup, animators setup to be culled that are outside the view frustum would be disabled by default, and only enabled once you get to see them...

    Repro steps are easy: (disclaimer: remember that in editor, the scene view camera also counts towards culling!)
    • Just make a scene with a lot of animators all around the camera (the more not visible upon startup, the better results), set them to Cull Completely.
    • Play the scene, look how many of them are updated within the profiler at Animator.Update > Animator.ApplyOnAnimatorMove (spoiler alert: all of them!).
    • Now walk/turn around a bit, in order to enable their culling, and eventually go back to initial position/orientation.
    • Look again within the profiler: WOW, dramatic decrease!

    Anyone having an idea on how to easily work around this, or if it's fixed/on the way? I haven't found anything mentioning it for now.
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    this is a know bug and was fixed in 5.4b3
     
  3. Le-nain

    Le-nain

    Joined:
    Nov 26, 2012
    Posts:
    62
    Thanks for posting this, I didn't have time between the reception of the QA email and you doing it for me.

    In the meantime, in case anyone stumbled upon this thread, my trick is to have a dedicated camera envisioning the whole scene (I used a camera with a 179° FoV, culling mask to Everything) which disables itself automatically after a small delay, allowing all the animator components to be initialized before it does so (0.2s works in my case) and thus making them receive the culling event.
     
    Mecanim-Dev likes this.
  4. DominikAbe

    DominikAbe

    Joined:
    Mar 20, 2015
    Posts:
    5
    Regression 5.4.2f2 has this bug again
     
  5. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    This issue could be related.
     
  6. thomas231

    thomas231

    Joined:
    Aug 18, 2016
    Posts:
    4
    We have the same problem that a gameobject will disable its animator only after seen once. Using Unity 5.4.3p3.
     
  7. Deleted User

    Deleted User

    Guest

    EXACT OPPOSITE problem, for two days now, my pilot is animated, at first start, and camera switch to cockpit view, the pilot is animated, as soon as I switch to third person view, ( full plane view, cockpit/pilot is hidden)...as sooon as I SWITCHED back to cockpit view, NO ANIMATION AT ALL! it just stops, does not matter how many times I call Play()...It just will not work the second time enabled...MAJOR BUG...I tried to force all components to be animated, no cull, 4 bones...weird because my landing gear is also animated and hidden as well, WITH NO PROBLEMS...ARGHHH!...

    so I can only play animation once , on recently enabled skin mesh.. if I hide it again, it stops forever.

    P-
     
    Last edited by a moderator: Jan 12, 2017
  8. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    please log a bug and we will investigate.

    In the meantime have you try to set your animator culling mode to always animate, at least it will always work while we investigate the issue
     
  9. Deleted User

    Deleted User

    Guest

    So I tried to emulate my landing gear, being it has the animation component on the same object as the skin mesh renderer, and is hidden by disabling that renderer by code, move it at the same hierarchy level., Settings: skin mesh renderer Quality 4 bones / Animation Component : culling type : Always animate.. | Update when Off Screen : True

    Upgraded to 5.5.04, Same thing -> All my animations are triggered by blend weights [The only difference from landing gear (they work/animated hidden/shown!). Like I said it works the first time the pilot is shown, never again after that, even if the animator says IsPlaying() = true!!! well maby so, but all blend weight animation stops, even though I verified input.

    Both controls and pilot are controlled the same way. from the same script, and both only work once.

    I wlll set up a blank project, to emphasize my problem and submit it!


    p-



    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CockpitAnimator : MonoBehaviour
    5.     {
    6.     public SkinnedMeshRenderer PilotMesh;
    7.     public SkinnedMeshRenderer ControlsMesh;
    8.     public Animation PilotAnimator;
    9.     public Animation ControlAnimator;
    10.     public Transform pilot_root;
    11.     public Transform LArm_root;
    12.     public Transform RArm_root;
    13.     public Transform LFoot_root;
    14.     public Transform RFoot_root;
    15.     public Transform CtrlThrottle_root;
    16.     public Transform CtrlRoll_root;
    17.     public Transform CtrlYaw_root;
    18.  
    19.     public AnimationClip PilotFlying;
    20.     public AnimationClip roll_left;
    21.     public AnimationClip roll_right;
    22.     public AnimationClip pitch_up;
    23.     public AnimationClip pitch_down;
    24.     public AnimationClip yaw_left;
    25.     public AnimationClip yaw_right;
    26.  
    27.  
    28.     public AnimationClip Throttle_up;
    29.     public AnimationClip Throttle_down;
    30.  
    31.     public AnimationClip CtrlFlying;
    32.  
    33.     public AnimationClip CtrlRollLeft;
    34.     public AnimationClip CtrlRollRight;
    35.     public AnimationClip CtrlPitchUp;
    36.     public AnimationClip CtrlPitchDown;
    37.     public AnimationClip CtrlYawLeft;
    38.     public AnimationClip CtrlYawRight;
    39.  
    40.     public AnimationClip CtrlThrottle_up;
    41.     public AnimationClip CtrlThrottle_down;
    42.  
    43.     public float SmoothFactor = .25f;
    44.     private float animWeight;
    45.  
    46.     private Animation a;
    47.     private Animation b;
    48.  
    49.     private AnimationState pilot_flying;
    50.     private AnimationState ctrl_flying;
    51.  
    52.     private AnimationState Roll_Left;
    53.     private AnimationState Roll_Right;
    54.  
    55.     private AnimationState Pitch_Up;
    56.     private AnimationState Pitch_Down;
    57.  
    58.     private AnimationState Yaw_Left;
    59.     private AnimationState Yaw_Right;
    60.  
    61.     private AnimationState ThrottleUp;
    62.     private AnimationState ThrottleDown;
    63.  
    64.     private AnimationState CtrlRoll_Left;
    65.     private AnimationState CtrlRoll_Right;
    66.  
    67.     private AnimationState CtrlPitch_Up;
    68.     private AnimationState CtrlPitch_Down;
    69.  
    70.     private AnimationState CtrlYaw_Left;
    71.     private AnimationState CtrlYaw_Right;
    72.  
    73.     private AnimationState Throttle_Up;
    74.     private AnimationState Throttle_Down;
    75.  
    76.  
    77.     [SerializeField]
    78.     private float m_Smoothing = 5f; // The smoothing applied to the movement of control surfaces.
    79.     private AeroplaneController m_Plane; // Reference to the aeroplane controller.
    80.  
    81.  
    82.     private void Awake()
    83.         {
    84.         // Get the reference to the aeroplane controller.
    85.         m_Plane = GetComponent<AeroplaneController>();
    86.         a = ControlAnimator;
    87.         b = PilotAnimator;
    88.  
    89.  
    90.         pilot_flying = b[PilotFlying.name];
    91.         pilot_flying.layer = 1;
    92.         pilot_flying.wrapMode = WrapMode.Loop;
    93.         pilot_flying.weight = 1f;
    94.         pilot_flying.speed = 1f;
    95.         pilot_flying.enabled = true;
    96.         //pilot_flying.blendMode = AnimationBlendMode.Blend;
    97.         //pilot_flying.AddMixingTransform(pilot_root);
    98.  
    99.         //Roll Left / Right
    100.         Roll_Left = b[roll_left.name];
    101.         Roll_Left.layer = 8;
    102.         Roll_Left.wrapMode = WrapMode.ClampForever;
    103.         Roll_Left.weight = 1;
    104.         Roll_Left.speed = 1f;
    105.         Roll_Left.enabled = true;
    106.         Roll_Left.blendMode = AnimationBlendMode.Blend;
    107.         Roll_Left.AddMixingTransform(RArm_root);
    108.  
    109.         Roll_Right = b[roll_right.name];
    110.         Roll_Right.layer = 8;
    111.         Roll_Right.wrapMode = WrapMode.ClampForever;
    112.         Roll_Right.weight = 1;
    113.         Roll_Right.speed = 1;
    114.         Roll_Right.enabled = true;
    115.         Roll_Right.blendMode = AnimationBlendMode.Blend;
    116.         Roll_Right.AddMixingTransform(RArm_root);
    117.  
    118.         //Pitch/Turn Left/ Right
    119.         Pitch_Up = b[pitch_up.name];
    120.         Pitch_Up.layer = 8;
    121.         Pitch_Up.wrapMode = WrapMode.ClampForever;
    122.         Pitch_Up.weight = 1;
    123.         Pitch_Up.speed = 1;
    124.         Pitch_Up.enabled = true;
    125.         Pitch_Up.blendMode = AnimationBlendMode.Blend;
    126.         Pitch_Up.AddMixingTransform(RArm_root);
    127.  
    128.         Pitch_Down = b[pitch_down.name];
    129.         Pitch_Down.layer = 8;
    130.         Pitch_Down.wrapMode = WrapMode.ClampForever;
    131.         Pitch_Down.weight = 1;
    132.         Pitch_Down.speed = 1;
    133.         Pitch_Down.enabled = true;
    134.         Pitch_Down.blendMode = AnimationBlendMode.Blend;
    135.         Pitch_Down.AddMixingTransform(RArm_root);
    136.  
    137.         //Yaw Left / Right
    138.         Yaw_Left = b[yaw_left.name];
    139.         Yaw_Left.layer = 5;
    140.         Yaw_Left.wrapMode = WrapMode.ClampForever;
    141.         Yaw_Left.weight = 1;
    142.         Yaw_Left.speed = 1f;
    143.         Yaw_Left.enabled = true;
    144.         Yaw_Left.blendMode = AnimationBlendMode.Blend;
    145.         Yaw_Left.AddMixingTransform(LFoot_root);
    146.  
    147.         Yaw_Right = b[yaw_right.name];
    148.         Yaw_Right.layer = 5;
    149.         Yaw_Right.wrapMode = WrapMode.ClampForever;
    150.         Yaw_Right.weight = 1;
    151.         Yaw_Right.speed = 1;
    152.         Yaw_Right.enabled = true;
    153.         Yaw_Right.blendMode = AnimationBlendMode.Blend;
    154.         Yaw_Right.AddMixingTransform(RFoot_root);
    155.  
    156.         //Throttle_Up Up/Doen
    157.         ThrottleUp = b[Throttle_up.name];
    158.         ThrottleUp.layer = 7;
    159.         ThrottleUp.wrapMode = WrapMode.ClampForever;
    160.         ThrottleUp.weight = 1;
    161.         ThrottleUp.speed = 1;
    162.         ThrottleUp.enabled = true;
    163.         ThrottleUp.blendMode = AnimationBlendMode.Blend;
    164.         ThrottleUp.AddMixingTransform(LArm_root);
    165.  
    166.         ThrottleDown = b[Throttle_down.name];
    167.         ThrottleDown.layer = 7;
    168.         ThrottleDown.wrapMode = WrapMode.ClampForever;
    169.         ThrottleDown.weight = 1;
    170.         ThrottleDown.speed = 1;
    171.         ThrottleDown.enabled = true;
    172.         ThrottleDown.blendMode = AnimationBlendMode.Blend;
    173.         ThrottleDown.AddMixingTransform(LArm_root);
    174.  
    175.         ctrl_flying = a[CtrlFlying.name];
    176.         ctrl_flying.layer = 1;
    177.         ctrl_flying.wrapMode = WrapMode.Loop;
    178.         ctrl_flying.weight = 1f;
    179.         ctrl_flying.speed = 1f;
    180.         ctrl_flying.enabled = true;
    181.  
    182.         //Rill Left / Right
    183.         CtrlRoll_Left = a[CtrlRollLeft.name];
    184.         CtrlRoll_Left.layer = 8;
    185.         CtrlRoll_Left.wrapMode = WrapMode.ClampForever;
    186.         CtrlRoll_Left.weight = 1;
    187.         CtrlRoll_Left.speed = 1f;
    188.         CtrlRoll_Left.enabled = true;
    189.         CtrlRoll_Left.blendMode = AnimationBlendMode.Blend;
    190.         CtrlRoll_Left.AddMixingTransform(CtrlRoll_root);
    191.  
    192.         CtrlRoll_Right = a[CtrlRollRight.name];
    193.         CtrlRoll_Right.layer = 8;
    194.         CtrlRoll_Right.wrapMode = WrapMode.ClampForever;
    195.         CtrlRoll_Right.weight = 1;
    196.         CtrlRoll_Right.speed = 1;
    197.         CtrlRoll_Right.enabled = true;
    198.         CtrlRoll_Right.blendMode = AnimationBlendMode.Blend;
    199.         CtrlRoll_Right.AddMixingTransform(CtrlRoll_root);
    200.  
    201.         //Pitch/Turn Left/ Right
    202.         CtrlPitch_Up = a[CtrlPitchUp.name];
    203.         CtrlPitch_Up.layer = 8;
    204.         CtrlPitch_Up.wrapMode = WrapMode.ClampForever;
    205.         CtrlPitch_Up.weight = 1;
    206.         CtrlPitch_Up.speed = 1;
    207.         CtrlPitch_Up.enabled = true;
    208.         CtrlPitch_Up.blendMode = AnimationBlendMode.Blend;
    209.         CtrlPitch_Up.AddMixingTransform(CtrlRoll_root);
    210.  
    211.         CtrlPitch_Down = a[CtrlPitchDown.name];
    212.         CtrlPitch_Down.layer = 8;
    213.         CtrlPitch_Down.wrapMode = WrapMode.ClampForever;
    214.         CtrlPitch_Down.weight = 1;
    215.         CtrlPitch_Down.speed = 1;
    216.         CtrlPitch_Down.enabled = true;
    217.         CtrlPitch_Down.blendMode = AnimationBlendMode.Blend;
    218.         CtrlPitch_Down.AddMixingTransform(CtrlRoll_root);
    219.  
    220.         CtrlYaw_Left = a[CtrlYawLeft.name];
    221.         CtrlYaw_Left.layer = 6;
    222.         CtrlYaw_Left.wrapMode = WrapMode.ClampForever;
    223.         CtrlYaw_Left.weight = 1;
    224.         CtrlYaw_Left.speed = 1f;
    225.         CtrlYaw_Left.enabled = true;
    226.         CtrlYaw_Left.blendMode = AnimationBlendMode.Blend;
    227.         CtrlYaw_Left.AddMixingTransform(CtrlYaw_root);
    228.  
    229.         CtrlYaw_Right = a[CtrlYawRight.name];
    230.         CtrlYaw_Right.layer = 6;
    231.         CtrlYaw_Right.wrapMode = WrapMode.ClampForever;
    232.         CtrlYaw_Right.weight = 1;
    233.         CtrlYaw_Right.speed = 1;
    234.         CtrlYaw_Right.enabled = true;
    235.         CtrlYaw_Right.blendMode = AnimationBlendMode.Blend;
    236.         CtrlYaw_Right.AddMixingTransform(CtrlYaw_root);
    237.  
    238.  
    239.         //CtrlYaw_root
    240.         //Throttle_Up Up/Doen
    241.         Throttle_Up = a[CtrlThrottle_up.name];
    242.         Throttle_Up.layer = 6;
    243.         Throttle_Up.wrapMode = WrapMode.ClampForever;
    244.         Throttle_Up.weight = 1;
    245.         Throttle_Up.speed = 1;
    246.         Throttle_Up.enabled = true;
    247.         Throttle_Up.blendMode = AnimationBlendMode.Blend;
    248.         Throttle_Up.AddMixingTransform(CtrlThrottle_root);
    249.  
    250.         Throttle_Down = a[CtrlThrottle_down.name];
    251.         Throttle_Down.layer = 6;
    252.         Throttle_Down.wrapMode = WrapMode.ClampForever;
    253.         Throttle_Down.weight = 1;
    254.         Throttle_Down.speed = 1;
    255.         Throttle_Down.enabled = true;
    256.         Throttle_Down.blendMode = AnimationBlendMode.Blend;
    257.         Throttle_Down.AddMixingTransform(CtrlThrottle_root);
    258.  
    259.         }
    260.  
    261.         //private void Start() {
    262.  
    263.         //if (!ControlAnimator.isPlaying)
    264.         //    ControlAnimator.CrossFade(CtrlFlying.name);
    265.         //if (!PilotAnimator.isPlaying)
    266.         //    PilotAnimator.CrossFade(PilotFlying.name);
    267.  
    268.         //}
    269.  
    270.  
    271.     private void Update()
    272.         {
    273.  
    274.         //animateStick(m_Plane.RollInput, m_Plane.PitchInput, m_Plane.YawInput, m_Plane.ThrottleInput);
    275.         }
    276.  
    277.     public void animateStick(float Yangle, float Xangle, float Zangle, float throttle)
    278.         {
    279.         //Debug.Log("Xangle: " + Xangle + "  Yangle: " + Yangle);
    280.         Roll_Left.weight = Mathf.Clamp(-Yangle, 0f, 1f);
    281.         Roll_Left.normalizedTime = -Yangle * .5f;
    282.         Roll_Right.weight = Mathf.Clamp(Yangle, 0f, 1f);
    283.         Roll_Right.normalizedTime = Yangle * .5f;
    284.  
    285.         CtrlRoll_Left.weight = Mathf.Clamp(-Yangle, 0f, 1f);
    286.         CtrlRoll_Left.normalizedTime = -Yangle * .5f;
    287.         CtrlRoll_Right.weight = Mathf.Clamp(Yangle, 0f, 1f);
    288.         CtrlRoll_Right.normalizedTime = Yangle * .5f;
    289.  
    290.         Pitch_Down.weight = Mathf.Clamp(Xangle, 0, 1f);
    291.         Pitch_Down.normalizedTime = Xangle * 2.5f;
    292.         Pitch_Up.weight = Mathf.Clamp(-Xangle, 0, 1f);
    293.         Pitch_Up.normalizedTime = -Xangle * 2.5f;
    294.  
    295.         Yaw_Left.weight = Mathf.Clamp(-Zangle, 0f, 1f);
    296.         Yaw_Left.normalizedTime = -Zangle * .5f;
    297.         Yaw_Right.weight = Mathf.Clamp(Zangle, 0f, 1f);
    298.         Yaw_Right.normalizedTime = Zangle * .5f;
    299.  
    300.         CtrlPitch_Down.weight = Mathf.Clamp(-Xangle, 0, 1f);
    301.         CtrlPitch_Down.normalizedTime = -Xangle * 2.5f;
    302.         CtrlPitch_Up.weight = Mathf.Clamp(Xangle, 0, 1f);
    303.         CtrlPitch_Up.normalizedTime = Xangle * 2.5f;
    304.  
    305.         CtrlYaw_Left.weight = Mathf.Clamp(-Zangle, 0f, 1f);
    306.         CtrlYaw_Left.normalizedTime = -Zangle * .5f;
    307.         CtrlYaw_Right.weight = Mathf.Clamp(Zangle, 0f, 1f);
    308.         CtrlYaw_Right.normalizedTime = Zangle * .5f;
    309.  
    310.         ThrottleUp.weight = Mathf.Clamp(throttle, 0f, 1f);
    311.         ThrottleUp.normalizedTime = throttle * 1.5f;
    312.         ThrottleDown.weight = Mathf.Clamp(-throttle, 0f, 1f);
    313.         ThrottleDown.normalizedTime = -throttle * 1.5f;
    314.  
    315.         Throttle_Up.weight = Mathf.Clamp(throttle, 0f, 1f);
    316.         Throttle_Up.normalizedTime = throttle * 1.5f;
    317.         Throttle_Down.weight = Mathf.Clamp(-throttle, 0f, 1f);
    318.         Throttle_Down.normalizedTime = -throttle * 1.5f;
    319.         //Debug.Log("Yaw .weights: " + Throttle_Up.weight + Throttle_Up.weight);
    320.  
    321.         }
    322.  
    323.         public void ShowSkinMesh (bool showMe) {
    324.         PilotMesh.enabled = showMe;
    325.         ControlsMesh.enabled = showMe;
    326.  
    327.         //if(showMe) {
    328.         //  
    329.         //    ControlAnimator.CrossFade(CtrlFlying.name);
    330.         if (showMe) {
    331.                         if (!PilotAnimator.isPlaying) {
    332.                                 Debug.Log("Pilot Not Animating!!!");
    333.                                 PilotAnimator.Play();
    334.                                     if (!PilotAnimator.isPlaying)
    335.                                         Debug.Log(" CALLED Play()  : Pilot STILL Not Animating!!!--------------------------------->>");
    336.                                         if (!PilotAnimator.isPlaying)
    337.                                             PilotAnimator.CrossFade(PilotFlying.name);
    338.                                         if (!PilotAnimator.isPlaying)
    339.                                             {
    340.                                                 Debug.Log("------------------------------->> Crossfade Default Clip : Pilot WILL Not Animate BY CODE !!! <<-------------------------------------");
    341.                                                // PilotAnimator.CrossFade(PilotFlying.name);
    342.                                             }
    343.                     else {
    344.                                 Debug.Log("Pilot Animating!!! - or Claims to be---------------->>");
    345.                         }
    346.                     }
    347.                 }
    348.         }
    349.  
    350.     }