• 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 Soviut · Apr 26, 2015 at 09:47 PM · assetdatabase

How to avoid two files in project view when creating a custom importer?

NOTE: I'm casting my net as far as possible and have asked the same question on Stack Overflow here.

I've created a ProTools CueSheet importer. It uses OnPostprocessAllAssets() to detect a files in the project that have a .cuesheet extension. It then runs those cuesheet files through my parser. This generates a ScriptableObject which is then turned into an asset via Database.CreateAsset().

The problem is, this leaves me with two files, the original cuesheet and the newly generated asset. Is there any way I can generate the asset in such as way that the original cuesheet acts as the asset, the same way textures or FBX files do?

 public class CueSheetPostProcessor : AssetPostprocessor {
     static string extension = ".cuesheet";
 
     static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) {
         foreach (string assetPath in importedAssets) {
             if (assetPath.EndsWith(extension, StringComparison.OrdinalIgnoreCase)) {
                 string newPath = assetPath + ".asset";
                 Session session = CueImporter.Load(assetPath);
                 AssetDatabase.CreateAsset(session, newPath);
                 AssetDatabase.SaveAssets();
             }
         }
     }
 }


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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Apr 27, 2015 at 10:25 AM

You should do the same what Unity's importer do: Add the derived assets as subassets to the original asset. That means you shouldn't use CreateAsset but AssetDatabase.AddObjectToAsset. That way your scriptable object will be a sub asset of your CueSheet.

Comment
Add comment · Show 4 · 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 Soviut · Apr 27, 2015 at 10:27 AM 0
Share

Interesting! Would this mean that dragging the original asset to an ObjectField that only accepts my scriptable object would still work? I'm going to test it, but for posterity, I think spelling it out here would be best.

avatar image Soviut · Apr 27, 2015 at 10:43 AM 0
Share

Trying to add my Session object to the cuesheet resulted in what seems like an endless recursive loop.

Bear in $$anonymous$$d, my "asset" is actually a file with a .cuesheet extension. According to the docs it states "...you should only add assets to '.asset' assets".

avatar image Bunny83 · Apr 27, 2015 at 11:17 AM 0
Share

@Soviut: Yep, i just did some tests myself. It looks like that only a few asset types support subassets. It's a pity that TextAsset doesn't allow subassets but $$anonymous$$aterial and AnimationClip does.

To answer your question: yes, in general you could drag the main asset and you should be able to assign the sub asset. The moment you add more than one sub asset, Unity usually allows you to expand the asset and shows them as sub items, just like the FBX importer does.

Hmm i'm not sure if there's some way to get that behaviour for TextAssets. The next problem is probably that ".cuesheet" isn't recognised as any kind of asset. Only ".txt" or ".xml" are translated as TextAsset as far as i know. However the problem stays the same that you can't add other assets as sub assets...

That's unfortunate.

avatar image Soviut · Apr 27, 2015 at 08:56 PM 0
Share

I don't even really want a container type, I just want the original cuesheet imported in place like a texture would be. That way I could drag it into my components that need it and only have a single file to deal with, should cuesheets be updated or deleted.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

When looping through assetbundle assetdatabase how do you reference a material object 0 Answers

Proper way to refresh asset 0 Answers

How to make a new path register in the AssetDatabase? 2 Answers

Custom assets give Missing (Mono Script) 0 Answers

Detect when a component has been removed. 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