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 BerggreenDK · Aug 01, 2011 at 10:33 AM · importeditor-scriptingassetpostprocessor

is it possible to have a global/static variable in the AssetPostprocessor script

I am trying to figure out if there is a constructor/start/awake kinda event on this object, but the documentation needs a little further development it seems at the moment.

I need to have somekinda static value or something that I can count, because when I do multiple imports, I get the event pr. model (which is great btw), but I need to calculate how many + assign certain values to the model, depending on how many I already have.

This one fires nicely:

 void OnPreprocessModel () 
 {
    ModelImporter proc = (ModelImporter) assetImporter; 
    Debug.Log(proc.assetPath);
 }

But is there any "before we start to import xx models" function that can initialize a counter etc.?

Edit #1 I would like to be able to have ZERO value before running the "Reimport" which can be fired with right mousebutton on any Ressource folder.

If its a static, it keeps going up and up and thats great while importing, but afterwards or before, I need to be able to set it back to zero for next run.

Reason is that I would like to build some kinda PROGRESS indicator for the import, like 234 of 3424 models.

Right now, my only option is to make a menu function that resets the static value or let the server return the "count". But the server ALSO needs to know when to start over.

Lastly, I cant seem to get WWWform to work with AssetsImporter ??? cant corutines be spawned from within this?

Comment
Add comment · Show 2
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 Waz · Aug 07, 2011 at 02:20 PM 0
Share

Possibly you are trying to achieve your ultimate goal (which is?) in a way that cannot work. The user can reimport assets whenever they want, individually or in bulk. If you need the number of a certain asset, then the only reliable way to do that would be to look for all of them whenever an asset is imported (or just when added or deleted if you only need the count). You could try to save this state and updating it incrementally, but you risk getting out of sync.

What is your ultimate goal?

avatar image BerggreenDK · Aug 07, 2011 at 02:46 PM 0
Share

okay, I'll try to explain it in the question. Just a sec! :o)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Paulius-Liekis · Aug 02, 2011 at 02:23 PM

Just define static variable (I don't know syntax for JavaScript) and then use it. If you want Init call for your static variables, you can always create "static bool initialized = false;", and then check for that in OnPreprocessModel and call your Init method if it hasn't been initialized.

Maybe you could just define a constructor for your AssetPostprocessor, although I can't remember how long Unity keeps the instance of each AssetPostprocessor.

Comment
Add comment · Show 6 · 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 BerggreenDK · Aug 02, 2011 at 08:14 PM 0
Share

C# syntax is fine by me. Regarding your static bool initialized, when will it be reset then? if I do a reimport, it should be initialized.

avatar image Paulius-Liekis · Aug 03, 2011 at 09:22 AM 0
Share

static variables live forever (read: as long as you have Unity running; they get reset if you recompile your scripts).

if you aren't satisfied with that lifetime, you can use PlayerPrefs :)

avatar image JustinLloyd1 · Aug 05, 2011 at 06:39 AM 0
Share

Static variables in C# do not "live forever." They last for as long as the object's lifetime. Once the object is marked for GC the static variable, like all other member variables within the class, become invalid.

avatar image BerggreenDK · Aug 07, 2011 at 01:39 PM 0
Share

Just tried to use the initialized in unity 3.4, first the editor crashed (which 3.4 does a lot I think) and then on reopening the project the first model import said initialized and the rest was already initialized. Problem is though, it does not go back to un-initialized even after the Reimport all function is run again. Problem still unsolved.

avatar image BerggreenDK · Aug 07, 2011 at 01:41 PM 0
Share

Constructor idea: Assets/Editor/FBXimporter.cs(35,14): error CS0542: `FBXimporter.FBXimporter()': member names cannot be the same as their enclosing type

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Creating a prefab in AssetPostprocessor.OnPostprocessAllAssets(). 1 Answer

Modify sprite geometry using AssetPostprocessor 0 Answers

How do I programmatically assign a GameObject to a prefab? 6 Answers

AssetPostprocessor (in dll) doesn't work when there's a compiler error in another script 0 Answers

Rename a clip using AssetPostProcessor 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