Different approach to loading XML data


Recently, I had a problem that my tool (custom Editor Window) wasn’t updating data I modified in XML file. I had to change focus from Unity to something else (for example internet browser) and then back to Unity to have the data updated in the tool.
I found the source of the problem. However, I don’t know why it wasn’t working as I wanted.
Here’s what I did:

//Loading XML file
TextAsset textAsset = Resources.Load<TextAsset>("File");
doc = new XmlDocument();
// (...)
//Saving XML file

It did worked to save newly made changes to the file but the tool didn’t update the data. I was looking for an answer when I changed the first three lines with:

doc = new XmlDocument();

and the tool magically started updating all the changes.

My question is essentially: Why my first approach didn’t work? Why loading the xml through Resources was forcing me to change system window focus? Is it because of some Unity Engine Resources reloading magic? Or did I just do that wrong way?

You need to call that one when you change an asset by code.