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 /
avatar image
5
Question by DannyB · Jun 10, 2013 at 05:35 PM · editorresourcestextasset

Force Unity to refresh a text asset (Resources folder)

Hello everybody,

I have created a small editor script that creates text files in my Resources folder.

I then noticed that after creating these files, Unity does not always refresh its memory of their content.

So after some research, I have found out about SetDirty, and I am using it like this on every file that I save in the Resources folder:

 static void SetDirty( string path ) {
     TextAsset textAsset = (TextAsset)AssetDatabase.LoadAssetAtPath( path, typeof(TextAsset) );
     EditorUtility.SetDirty( textAsset );
 }

This helps things a little, but still in order for Unity to re-import these assets and their refreshed content, I need to alt-tab away from Unity, and back in.

Am I doing anything wrong, have I missed something, or is this just the way it works?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
16
Best Answer

Answer by Veehmot · Jun 10, 2013 at 08:02 PM

As you found out, AssetDatabase.Refresh is the right choice when you need to reimport everything; that's what Unity does when you edit a file.

But if you want to refresh a single file, you should use AssetDatabase.ImportAsset.

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 DannyB · Jun 10, 2013 at 08:06 PM 0
Share

Thanks. Also helpful indeed. I wonder if I can skip SetDirty if I use ImportAsset? EDIT: Looks like there is no need for my SetDirty call, so this answer is better.

avatar image Veehmot · Jun 10, 2013 at 08:12 PM 0
Share

The way you are using it, yes. SetDirty tells the engine you did a change to an asset so it should be saved. You are marking the asset as dirty right after you import, but you should mark it if you ever do a change to the asset using scripting.

But being a TextAsset, there's no need at all to use SetDirty, you can freely edit your text outside Unity and reload it using Refresh.

avatar image DannyB · Jun 10, 2013 at 08:14 PM 0
Share

Excellent! Thanks buddy, clear and helpful.

avatar image Spicyruby · Nov 06, 2020 at 03:01 AM 0
Share

Thanks, works for me!

avatar image
3

Answer by DannyB · Jun 10, 2013 at 07:30 PM

Found the answer: AssetDatabase.Refresh() seems to make everything right.

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 anamta93 · Jul 19, 2016 at 08:42 AM 0
Share

Thank you so so much :D saved my day

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

17 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

Related Questions

How to know if a GameObject is a prefab? 15 Answers

Clearing Editor References when Building for Mobile 1 Answer

Do I need to use SetDirty in my editors if I'm using SerializedProperties? 1 Answer

Finding all asset textures with width > 1024 1 Answer

Resources.Load wont read text file 6 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