Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 BenMeijering · Feb 06, 2013 at 09:08 AM · assetpostprocessorsubversion

AssetPostprocessor using configuration stored in asset

Hi,

I've stumbled across the following problem and was hoping anyone could help me out.

In my project, I have implemented a postprocessor class. The postprocessor configuration is defined in a class derived from ScriptableObject and is stored in settings.asset.

So, when the postprocessor encounters an asset which needs processing, it loads the settings.asset and figures out what should be done.

However, when I check out this project (SVN) and open it for the first time, the settings.asset file is imported after the files that need processing and cannot be used.

I have already tried using:

 private void OnPreprocessModel()
 {
     ....
     AssetDatabase.ImportAsset(settingsPath, ImportAssetOptions.ForceSynchronousImport);
     settings = (Settings)AssetDatabase.LoadAssetAtPath(settingsPath, typeof(Settings));
     ....
 }

But unfortunately this does not work.

Does anyone know how I could get this to work without having to resort to a different type of configuration file (e.g. xml)

Any help would be appreciated.

Cheers,

Ben

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Zonerunner · Jun 12, 2015 at 01:00 AM

So even though this question was asked long ago I hit the same problem and had to faff around to get something that worked so here goes The Internet.

I can't see a way to override the unity import order so what I did instead is detect when my "config file" asset was imported and use that moment to kick off reimporting my model asset. Did so like this:


static void OnPostprocessAllAssets (string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) 
{
    foreach (var str in importedAssets)
    {
        Match match = Regex.Match( str, "(^.*?).asset$" );
        if( match.Success )
        {
            AssetDatabase.ImportAsset( match.Groups[ 1 ].Value + ".fbx", ImportAssetOptions.ForceUpdate );
        }    
    }
}

So what happens in a reimport all\initial checkout is the following: 1)model gets imported, can't find the config file 2)config gets imported 3)model file gets imported again and now the config file exists

Obviously this is not the most efficient thing in the world but it does have the virtue of working. If anyone else has a better way of doing this I'd be interested to hear.

Comment
Add comment · 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
0

Answer by BMayne · Jun 12, 2015 at 01:17 AM

Hey there,

An option that is not blatantly obvious would be to use a ScriptableSingleton class. The advantage of this class is the fact that you tell it when to load. They are ScritpableObjects that can save outside of the Unity project.

The only sad thing is that you can't use this class out of the box since one of the attributes it uses is internal but you can recreate all the functionality by using

InternalEditorUtility.LoadSerializedFileAndForget && InternalEditorUtility.SaveToSerializedFileAndForget

Cheers,

Comment
Add comment · 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

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

11 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

Related Questions

How to write pixels to a lightmap 2 Answers

AssetPostprocessor reference to asset being processed? 1 Answer

Texture format not saved in asset bundles 0 Answers

Use UserData from FBX to initialize member variables of a script 0 Answers

Will Unity 3 iPhone Pro support subversion for version control 2 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