Animator doesn't allow to desactive object

I have one object with multiples components.
I also have an animation where I show and hide some of that components. Just to show inside.
To do it I just animate the Active to true or false.
And here is the problem, when I am not playing the animation and only using the model in runtime mode, the components that I had animated Active parameter, now, in runtime doesn’t allow me to hide the same components in realtime.
Very simple test:
-Create one box
-create an animation where we hide it
-create one button in scene with an script to SetActive() to true or false.
Thats it. The script now cant hide anymore the object.

Some idea to bypass it?

Bump

We have to initial but for me ugly approaches:
-Move the object to a far way from the camera clip area. (will do a unnecessary processing)
-Keep using SetActive but disable the animator. (in some cases is a problem when we have transitions with others)
-When possible, not my case, disable the Mesh Renderer (for empty gameObjects like used to repo the pivot, doesnt work)

Just make sure the top level object is active, your animation runs on the top level object, and the hierarchy isn’t changing order. It works fine this way. You have problems when you modify object order inside the hierarchy or deactivate the animation component.

1 Like

In my case I have it:

Body
   BodyGroup  (Animator)
       DoorsGroup (sometimes I have here disabling the object group. If I have it here I haven't others like in Door1 )
           Doors1Pivot
                Door1  (in animation I have a frame where I disable it)
           Doors2Pivot
                Door2  (in animation I have a frame where I disable it)

Is this format doesnt work for me. Do you can to make it work?

9765357--1398915--upload_2024-4-11_18-26-22.png

Make sure you have Write Defaults(x) disabled in your Animator state.

See the checkbox here? Turn it off.

1 Like

I am missing somethying and I dont know what.

9765402--1398939--upload_2024-4-11_18-46-59.png

9765402--1398942--upload_2024-4-11_18-47-12.png
For me the same problem.

In my script I click over an object and if this object have a MeshRenderer so I can hide it and is very simple.

selected.SetActive(state);

But only works if I disable the animator. With animator and frames disabling the object, that object cant be SetActive(false). The object simply doesnt disappear.

I think that I understand the LaneFox approach:
SomeParent
SomeChildForScript (by script we disable this object)
SomeChildForAnimation (by animation we disable this object)

I need to change a lot in my code but make sense…Can work…

I found this phrase:
As soon as there is an Animator where any animation state holds only any keyframe on a certain property, the Animator “locks” that property against any changes via script since the Animator is executed almost latest within one frame.

So maybe is impossible to deal with it. Probably only disabling the animator…

I am reading that maybe is possible to do after the animator with:
MonoBehaviour.LateUpdate()

But I have my script:

public void Hide(GameObject selected, bool state)
{
    selected.SetActive(state);
}

Do U need to call my method in LateUpdate()?

You can mix and match animator and LateUpdate().

Ideally, try NOT to mix and match though because it becomes difficult to remember what you are doing.

You can also control sub-items through either animator layers or else through a separate animator / animation.

Here is some timing diagram help… see animation section.

1 Like

-A very nice video where this guy show a very similar with my issue. With one solution.

-One thread that discuss this issue

The best solution is try to disable the Animator and enable when use it.