[solved] Disable TextAsset Cache?

Hello,

My problem is that Unity is caching text files, so if I modify those files in-editor, I have to restart Unity for those edits to take effect.

More specifically, I’m making a custom EditorWindow that accepts data and outputs a text file (.txt) to the resources folder using a System.IO StreamWriter. At runtime, I create a component that accesses that text file using Resources.Load() to load it as a TextAsset.

Calling “Caching.CleanCache()” does nothing for me, it must be a tool for web assets only.

Anyone? This seems to be the only way to output text at edit time, include it in a build, and load it in at runtime. It’s very irritating because every time we make small edits to those files (which we do often) we have to restart Unity or our changes won’t take immediate effect.

EDIT: I’ve been experimenting and googling around, people have reported running into this problem since 2009, but nobody ever seems to get it solved. This should be simple, all I want is to make changes to a text file in my editor and have them take effect immediately without restarting. There must be a library/temp file or something I can delete to lose the cached resources.

VICTORY!

The tiny, well-hidden piece of code I was looking for was “UnityEditor.AssetDatabase.Refresh();” which is the equivalent of clicking the “Assets” dropdown in Unity and selecting “Refresh”.

For others looking to make this work, remember “UnityEditor” is an editor-only namespace, so make sure that code gets excluded from builds. (#if UNITY_EDITOR, or put your script in a folder called “Editor” inside your Assets folder)

1 Like

This was super helpful! I thought I was going crazy, as it seemed to refresh when I reloaded the data in a separate text editor (Notepad++). Thought there must be some caching going on, but would’ve taken awhile to find this.

Thank the lord for this answer. you saved are ass in the past