Search Unity

Question Executing a method on a Editor script after import

Discussion in 'Scripting' started by RoughSpaghetti3211, Apr 23, 2022.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    I was wondering if someone could please help me. I have a static file outside my project. eg

    Code (CSharp):
    1.    
    2. public static class MyExternalFile
    3.     {
    4.         public static void OnImported()
    5.         {
    6.             Debug.Log("Hello");
    7.         }
    8.     }
    9.  
    In the editor, I'm using a ScriptableWizard to copy the file(s) into my project. Is there a way to execute my OnImported method right after the script has been copied over? The class and the file name will change from file to file but each file will have a OnImported() method.

    The closed I've got to get this work was using a [UnityEditor.Callbacks.DidReloadScripts()] attribute but that seems to only work the second time around. Is the file exists in the project, and I delete it and then copy the same file back it does work. Is this because there is an existing meta file? Is there a way to force the callback or a better way of handling this? Any suggestions would be appreciated