I want to change AnimationEvent.FunctionName
but the value keep return back. Here is my code, can anyone show me where I do it wrong? (look comment with ! mark)
using UnityEngine;
using UnityEditor;
namespace Projectz
{
public class AnimationEventFunctionNameChanger : MonoBehaviour
{
private AnimationClip _animationClip;
private string _oldName;
private string _newName;
private void Start()
{
ChangeEventFunctionName();
}
private void ChangeEventFunctionName()
{
if(_animationClip == null)
{
Debug.Log("_animationClip is null.");
return;
}
for (int i = 0; i < _animationClip.events.Length; i++)
{
Debug.Log($"({i}) functionName= {_animationClip.events[i].functionName}");
if (_animationClip.events[i].functionName != _oldName) continue;
Debug.Log($"Found equal name.");
_animationClip.events[i].functionName = _newName; //! for some reason this value always change back.
Debug.Log($"functionName= {_animationClip.events[i].functionName} || _newName= {_newName}");
EditorUtility.SetDirty(_animationClip);
}
}
}
}