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.
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.
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)
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…