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.
  2. Dismiss Notice

Possible to know if Animator is being culled via Script?

Discussion in 'Animation' started by CreativeBytesStudios, Feb 3, 2017.

  1. CreativeBytesStudios

    CreativeBytesStudios

    Joined:
    Jun 5, 2014
    Posts:
    9
    When I change the culling type on an Animator to Cull Completely, I can see in the profiler that the Animator.ApplyOnAnimatorMove removed the object when it is no longer in the camera view.

    I'd like to optimize some logic in a script based on if we aren't animating, but I couldn't see any property on the Animator that would tell me if it's animating or being culled or not.

    Does that exist?
     
    oriolmanya likes this.
  2. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    yes basically the animator does register itseft to all renderer found under the animator component
    And then renderers send the appropriate msg when they become visible or not.
    If any renderer are visible then the animator need to be updated

    you can attach your script to the same callback

    https://docs.unity3d.com/ScriptReference/Renderer.OnBecameVisible.html
    https://docs.unity3d.com/ScriptReference/Renderer.OnBecameInvisible.html
    https://docs.unity3d.com/ScriptReference/Renderer-isVisible.html
     
  3. oriolmanya

    oriolmanya

    Joined:
    Jul 4, 2012
    Posts:
    50
    I tried and it works as @Mecanim-Dev says, the only problem is that the GameObject where the Animator is, has to have a Renderer, and maybe you only want Renderers on the children.

    Maybe should be better explained on OnBecameVisible() documentation that Animators also have this feature.

    Keep in mind as well that you cannot check that culling behaviour on Editor View, because it is considered a Camera. To make sure it works, I have a look at the transforms of objects outside any camera / view to see if they where moving.

    Hope it helps.

    Thanks anyway!
     
    Last edited: Apr 7, 2020
  4. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    405
    Can someone confirm the correct behaviour ?
    - Animator culls with renderers in the child hierarchy of the animator
    or
    - Animator culls with the renderer on the GO itself ? (That would be damn wierd ...)

    However I do have this issue where my animators are culled although they child renderers (Sprite Renderers) are in full view. I believe it's kindof a "bug" as :

    At start of the animation the child renderers are of size 0.001 and this prbly randomly discarded as being visible and so the animator discards itself without the chance to scale up the child renderers.