Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
9
Question by DtBeloBrown · Apr 08, 2010 at 05:33 PM · editor-scriptinggenerationassetpostprocessor

Can I get a callback when scripts have finished compiling?

I was unable to find a callback for use in an editor script to let me run code when compilation has finished. It might sound a little crazy at first, but such a callback could be useful for code generation techniques.

AssetDatabase.ImportAsset can be called on a script to force compilation immediately but will return before compilation is complete.

AssetPostProcessor doesn't appear to be able to call back for scripts.

C# can't have anything like Eval().

If anyone can think of a way to accomplish this please answer.

("YO DAWG I HEARD YOU LIKE EDITOR SCRIPTS...")

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
42
Best Answer

Answer by guavaman · Apr 25, 2015 at 06:32 PM

Use the attribute DidReloadScripts like this:

 [UnityEditor.Callbacks.DidReloadScripts]
 private static void OnScriptsReloaded() {
     // do something
 }

Note that this does not run in batch mode when doing a build with the -quit flag even if scripts are reloaded.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JS_Richard · Jul 16, 2018 at 01:09 PM 1
Share

As a re$$anonymous$$der: You have to use 'static' in order for it work. It makes sense in hindsight, but it took me a short while to figure out. Nothing else seems to be needed.

avatar image Hanh · Aug 09, 2018 at 07:12 AM 0
Share

Perfect! It's exactly what I am looking for.

avatar image
1

Answer by yakswa98 · Jun 10, 2017 at 06:50 AM

      public class YourEditorWindow : EditorWindow
      {
       static YourEditorWindow instance = null;
      
      [MenuItem("YourMenu")]
       void Init()
       {
           instance= GetWindow(typeof(YourEditorWindow )) as YourEditorWindow ;
           instance.Show();
       }
       void OnGUI()
       {
           if (instance==null)
           {
               Init();
               return;
           }
      }

if script is recompiled all the static value is null and than you reopen your editorwindow

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image IgnGrillo · Jan 18, 2021 at 09:30 PM 0
Share

I could not find this information on any documentation page.

You saved me a good deal of time with this, thank you. .

avatar image
-1

Answer by DtBeloBrown · Apr 22, 2010 at 09:26 PM

There isn't a callback, but you can poll on this variable: EditorApplication.isCompiling

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eskivor · Apr 30, 2020 at 10:21 PM 0
Share

The sample code in EditorApplication.isCompiling's official page does not work :(

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Execute a Runtime LevelGenerator in Edit-Mode 1 Answer

change textures without changing the original file 0 Answers

(Editor Scripting) Is it possible to generate MenuItems? 2 Answers

How can I make a text file immediately appear in my project from an AssetPostProcessor script? 1 Answer

Can you make an EditorWindow pop up and block the asset import process while it's open? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges