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 /
  • Help Room /
avatar image
7
Question by alexnode · Apr 08, 2010 at 02:28 PM · beginnerresourcesassetpostprocessor

How to start coding with AssetPostprocessor?

I am a beginner in coding but I see the necessity for accessing the AssetPostprocessor. Apart from the official Documentation Here I found this very good example for automatically creating collision meshes, in c# (hmmm) Here I found examples like that very helpful to understand how things work. Are there any other nice examples around? Thanks

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
12
Best Answer

Answer by duck · Apr 08, 2010 at 05:00 PM

What you already have should be more than enough to get you started. Here's another very simple example which automatically attaches a script to any object with "enemy" in the name:

using UnityEngine; using UnityEditor; using System.Collections;

public class ModelPostProcessor : AssetPostprocessor {

 void OnPostprocessModel (GameObject g) {
     Apply(g.transform);
 }

 void Apply (Transform transform)
 {
     if (transform.name.ToLower().Contains("enemy"))
     {
         transform.gameObject.AddComponent<Enemy>();
     }

     // Recurse
     foreach (Transform child in transform)
     {
         Apply(child);
     }
 }

}

You can use this system of detecting keywords in the model's name for a variety of very useful gameobject modifications during the import process - typically I use it for:

  • adding scripts to objects
  • adding colliders to objects
  • adding rigidbodies to objects
  • removing the renderer from objects (eg, if I'm using proxy collision objects)

You can also do similar processing based on artist-assigned model properties, using the incredibly large function, "AssetPostprocessor.OnPostprocessGameObjectWithUserProperties".

There are also other AssetPostprocessor functions, such as OnPostprocessAllAssets, which you can use for different tasks, the most useful I find being to automatically match up sets of related textures (such as bump map textures, reflection textures, lightmap textures) according to a naming convention, and create and assign the appropriate Materials.

Eg, if you had a base material with a texture called "Road_Diffuse.png", you could have the asset post processor automatically scan for "Road_Bumpmap.jpg" and "Road_Lightmap.jpg", and automatically create and assign a Material which uses the Lightmapped Bumped Specular shader, with all the textures already assigned!

(I will add examples of this to this answer when I have time - don't have time right now!)

Here's another example to apply settings to audio files:

using UnityEngine; using UnityEditor; using System.Collections;

class MyAudioPostprocessor : AssetPostprocessor {

 void OnPreprocessAudio () {

     AudioImporter audioImporter = (AudioImporter) assetImporter;
     audioImporter.format = AudioImporterFormat.Compressed;

 }

}

These kinds of automatic processing of art assets are invaluable when you have separate artists producing scenes with many elements which would otherwise need sorting out in Unity by hand after importing. You can then just give your artists the naming conventions to use.

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 alexnode · Apr 08, 2010 at 05:29 PM 0
Share

ACE!!! Thanks, yep yep .. by name and WithUserProperties seems a really good way to go ! Thanks again.

avatar image Statement · Jan 12, 2011 at 10:06 PM 0
Share

"using the incredibly large function, AssetPostprocessor.OnPostprocessGameObjectWithUserProperties". You made me roll over and laugh and then some. That is a beast! The king of codes!

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

No one has followed this question yet.

Related Questions

How can I start learning Unity fast? ( List Of Tutorials ) 14 Answers

raw folder and files can not be found after build 0 Answers

What is "Update.ScriptRunBehaviourUpdate"? 0 Answers

Resources.Load() doesn't work unless load path is hard coded. 1 Answer

All collectibles before next scene? 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