When I disable a GameObject, I found all values inside the Animator become to default. So is any ways to keep them, or recover them after enabled the GameObject?
Or the only way can do this is manually save them?
Well, there is a way I found that can solve this problem without manually save each parameter.
Firstly, by using Animator.parameters
(Documentation), we can get all parameters in the Animator. Note that it does not include the value.
Animator.parameters
is an array of the classAnimatorControllerParameter
, which includes a property called AnimatorControllerParameterType type
, which is an enum:
public enum AnimatorControllerParameterType
{
Float = 1,
Int = 3,
Bool = 4,
Trigger = 9
}
So now, we can simply call the methods such as GetBool, GetFloat in a loop to get all the variable, then use another loop to set them by calling the method such as SetBool and SetFloat