0
\$\begingroup\$

I am loading my assets and tile information through YAML files.

While working on the game, I needed to quickly change some values and test them in-game, and I realized I could just re-load the YAML information without having to restart.

However, before my files are processed by my YAML parser, they are loaded by using Resources.LoadAll, like this:

    foreach (var buildingTileType in Resources.LoadAll(Settings.BUILDING_TILES_PATH, typeof(TextAsset)))
    {
        var buildingTile = Deserializer.Deserialize<BuildingTile.Initializer>(((TextAsset) buildingTileType).text);
        BuildingTileInstances.Add(buildingTile.Name, buildingTile.CreateInstance());
    }

When I want to reload my defs, I clear the BuildingTileInstances dictionary and call the def-loading method again. However, I noticed the values were remaining the same until I restarted the game.

I've read that Resources.Load actually caches your files for optimization, and in this case, I'd like to somehow clear that cache to allow for live reloading.

I've tried using Resources.UnloadUnusedAssets() and Caching.ClearCache(), but none of them worked. Is there any way to achieve this?

\$\endgroup\$
3
  • \$\begingroup\$ I don't think this is the Resources system caching the file contents, but the underlying AssetDatabase that needs to be told to re-import the asset. As an aside, Resources.Load is an old and inefficient way to look up assets at runtime - you might want to switch to using Addressables instead. \$\endgroup\$
    – DMGregory
    Commented Jun 25, 2021 at 15:48
  • \$\begingroup\$ AssetDatabase.Refresh did it. I'd love to accept your answer if you submit it. I've also looked into addressables, but it seems there isn't a very straightforward tutorial on how to migrate from using Resources.LoadAll to this new system. Thank you for the information, though. \$\endgroup\$
    – caleidon
    Commented Jun 25, 2021 at 16:15
  • \$\begingroup\$ I'm tied up at the office just now, so feel free to post your own answer showing how you used AssetDatabase.Refresh. \$\endgroup\$
    – DMGregory
    Commented Jun 25, 2021 at 16:19

1 Answer 1

1
\$\begingroup\$

Calling AssetDatabase.Refresh() before using Resources.LoadAll seems to have cleared the cache and everything works as intended.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .