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
0
Question by patrik-org · Feb 08, 2019 at 12:08 PM · editoreditor-scriptingimporting assetsasset bundleseditor extension

Queue method to be called after asset processor is done

Is there a way to queue a C# method to be called in the unity editor after assets has been imported?

I'm trying to build AssetBundles from within an AssetPostprocessor and get the following error:

 Cannot build AssetBundles while imports of assets are in progress. Are you trying to build AssetBundles from within an AssetPostprocessor?

A related problem is executing some code after editor exits play-mode.

Any solution to these problems?

Comment
Add comment · Show 7
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 patrik-org · Feb 08, 2019 at 12:28 PM 0
Share

Found answer to the latter question about code executing when editor exits play-mode: http://answers.unity.com/answers/550598/view.html

Still need to be able to queue a method to be called after import of assets though.

avatar image RobAnthem · Feb 08, 2019 at 03:44 PM 1
Share

Actually you just need to do what unity is telling you to do. Create class that inherits from AssetPostprocessor and implement the PostProcession functions for the objects you want to handle.

For example, if you're trying to handle 3D models when they are imported. You would implement the OnPostprocess$$anonymous$$odel function.

 using UnityEngine;
 using UnityEditor;
 
 // Adds a mesh collider to each game object that contains collider in its name
 public class Example : AssetPostprocessor
 {
     void OnPostprocess$$anonymous$$odel(GameObject g)
     {
         Apply(g.transform);
     }
 
     void Apply(Transform t)
     {
         if (t.name.ToLower().Contains("collider"))
             t.gameObject.AddComponent<$$anonymous$$eshCollider>();
 
         // Recurse
         foreach (Transform child in t)
             Apply(child);
     }
 }


Or if you're looking to do things when any object is imported you can just implement the OnPostprocessAllAssets.

 using UnityEngine;
 using UnityEditor;
 
 class $$anonymous$$yAllPostprocessor : AssetPostprocessor
 {
     static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
     {
         foreach (string str in importedAssets)
         {
             Debug.Log("Reimported Asset: " + str);
         }
         foreach (string str in deletedAssets)
         {
             Debug.Log("Deleted Asset: " + str);
         }
 
         for (int i = 0; i < movedAssets.Length; i++)
         {
             Debug.Log("$$anonymous$$oved Asset: " + movedAssets[i] + " from: " + movedFromAssetPaths[i]);
         }
     }
 }



avatar image patrik-org RobAnthem · Feb 08, 2019 at 03:52 PM 0
Share

Hi Rob, I appreciate your answer. But the error doesn't tell me to do it in an AssetPostprocessor, it's guessing that i'm trying to do that and saying that I can't :)... which is the problem, I'm trying to do in an asset post-processor script, because I need to build the asset bundles after some assets have been processed. I kinda solved it by doing it when the user clicks on play, but there might be problems with that solutions - e.g. some edge case when the user adds some assets, never clicks on play and builds the project - then the asset bundles never gets built.

avatar image RobAnthem patrik-org · Feb 08, 2019 at 03:55 PM 0
Share

Well this is Editor code anyway, it cannot run on a cimpiled game... what exactly are you TRYING to accomplish? $$anonymous$$aybe it would be better to help with that ins$$anonymous$$d of trying to deter$$anonymous$$e how to solve the error.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

140 People are following this question.

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

Related Questions

Custom Inspector for a List ? 2 Answers

How to make multiple EditorWindows dock together? 0 Answers

Is there any way to make a timeline feature in editor scripting? 1 Answer

Finding a GameObject in an editor script based on position 2 Answers

Converting XML-files into assets 1 Answer


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