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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Kevin Harris · Aug 20, 2012 at 02:17 AM · editor-scriptingassetpostprocessorautomation

How should prefabs be changed automatically based on updating a text file?

I'm currently using a text file to define data for a Monobehaviour. Ideally, any changes to the text file would result in calling an editor script to automatically update the Monobehaviour. My best guess of where to hook into the asset import pipeline is OnPostProcessAllAssets, but this leads to a few problems:

  • The Monobehaviour's values are changed until the scene is deserialized:

       OnPostProcessAllAssets {
             // Find the game object & monobehaviour
             // Read the text file
             // Update the monobehaviour variables
             EditorUtility.SetDirty(theGameObject)
             EditorUtility.SetDirty(theBehaviour)
         }
    
    

    This seems to fail because Unity doesn't properly save the changes. The editor indicates that changes have been made, and they are lost upon either manually saving or playing the scene.

  • Unity freezes:

       OnPostProcessAllAssets {
             // Find the game object & monobehaviour
             // Read the text file
             // Update the monobehaviour variables
             EditorUtility.SetDirty(theGameObject)
             EditorUtility.SetDirty(theBehaviour)
             EditorApplication.SaveAssets()
         }
    
    

    This causes the asset importer to enter an infinite loop, each time calling OnPostProcessAllAssets(). This happens regardless of using EditorApplication.SaveAssets() or AssetDatabase.SaveAssets(). However, when calling a function to perform the same action (via the MenuItem attribute), this works correctly; the problem is how to automate changes based on the text file being updated.

  • Attempting to manage the number of times OnPostProcessAllAssets is called also fails to work, as the *.SaveAssets() methods don't appear to block or expose a means to wait until their completion. The number of times that OnPostProcessAllAssets is called is also indeterminate, and so counting also fails to achieve the results I'm after.

Similar questions include

  • How can I create a custom import object. Like the questioner there, I'm hoping to do create updates at import instead of runtime. This question differs in that it asks about updating a prefab instead of creating new assets.

  • Import own formats with asset importer similarly asks about creating new objects, not updating an existing asset.

  • Custom Asset Files asks about creating objects programmatically using menu items, not automatically updating existing prefabs.

Is there a means to automatically update a prefab based on changes to a text file?

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
0

Answer by no · Oct 09, 2012 at 09:57 AM

I did not even know that you could edit prefabs... but this is my best answer, I figured I should help you if you helped me: Have you tried importing the text file into the project, choosing your editor in Unity then double clicking it from the resources? Each time you save with your text editor/IDE I would imagine it acts similar to finishing edits of scripts in Monodevelop, except with whatever program you want. Maybe this was too simple an answer. Please forgive my ignorance.

Good luck with your 'Bushudo' project in Boo!

I'd be interested in playing given that 私は日本語のべんきょします

Comment
Add comment · Show 1 · 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 Kevin Harris · Oct 09, 2012 at 02:00 PM 0
Share

Thanks for the suggestion and wishes! I'm using the process that you suggested–––adding the text file into the project, opening it from within Unity, and then saving it there. $$anonymous$$y question is about having Unity process the file using AssetPostprocessor.OnPostprocessAllAssets or something similar to automatically update other objects in the scene.

お互いに頑張りましょう!

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

9 People are following this question.

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

Related Questions

Can you make an EditorWindow pop up and block the asset import process while it's open? 0 Answers

Modify sprite geometry using AssetPostprocessor 0 Answers

How to use OnWIllDeleteAsset - Not being called 2 Answers

How can I make a text file immediately appear in my project from an AssetPostProcessor script? 1 Answer

is it possible to have a global/static variable in the AssetPostprocessor script 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