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.

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.

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