- Home /
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?
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 私は日本語のべんきょします
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
Follow this Question
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