Search Unity

Question Change Object.name on asset rename

Discussion in 'Editor & General Support' started by Djayp, Oct 19, 2020.

  1. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    114
    Hello ! I'm trying to replace '@' with '/' in the AnimationClip's internal name, and it works great on asset creation/move :


    Problem is it doesn't work when I'm just renaming assets. Here is the code :
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.IO;
    4.  
    5. class AnimationPostprocessor : AssetPostprocessor
    6. {
    7.     private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    8.     {
    9.         FindAndTrySetInternalClipName(importedAssets);
    10.         FindAndTrySetInternalClipName(movedAssets);
    11.     }
    12.  
    13.     private static void FindAndTrySetInternalClipName(string[] assets)
    14.     {
    15.         for (int i = 0; i != assets.Length; i++)
    16.         {
    17.             string path = assets[i];
    18.             if (!path.Contains("@") || !string.Equals(Path.GetExtension(path), ".anim")) continue;
    19.  
    20.             AnimationClip clip = AssetDatabase.LoadAssetAtPath<AnimationClip>(path);
    21.             clip.name = clip.name.Replace('@', '/');
    22.         }
    23.     }
    24. }
    I tried a bunch of solutions (SerializedObject, AssetModificationProcessor, ForceReserializeAssets, GetPostprocessOrder) but none of them work. Any idea ?
     
  2. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    114
    We really need some solution here. Working with Animator Layers and Overrides, it becomes a real mess.
    upload_2020-10-25_8-45-24.png