Skip to content

Commit 0f3c8a3

Browse files
committed
Fix hash ids not changing when name changes in editor
1 parent c5e2b52 commit 0f3c8a3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Editor/AnimatorParameterPropertyDrawer.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,29 @@ namespace Zigurous.Animation.Editor
77
public sealed class AnimatorParameterPropertyDrawer : PropertyDrawer
88
{
99
private SerializedProperty _name;
10+
private SerializedProperty _hash;
1011

1112
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
1213
{
1314
if (_name == null) {
1415
_name = property.FindPropertyRelative("_name");
1516
}
1617

18+
if (_hash == null) {
19+
_hash = property.FindPropertyRelative("_hash");
20+
}
21+
1722
EditorGUI.BeginProperty(position, label, property);
1823
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
19-
_name.stringValue = EditorGUI.TextField(position, _name.stringValue);
24+
25+
string name = EditorGUI.TextField(position, _name.stringValue);
26+
27+
if (name != _name.stringValue)
28+
{
29+
_name.stringValue = name;
30+
_hash.intValue = Animator.StringToHash(name);
31+
}
32+
2033
EditorGUI.EndProperty();
2134
}
2235

Runtime/DataStructures/AnimatorParameter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace Zigurous.Animation
1212
[System.Serializable]
1313
public struct AnimatorParameter
1414
{
15+
[SerializeField]
16+
[HideInInspector]
1517
private int _hash;
1618

1719
/// <summary>

0 commit comments

Comments
 (0)