Skip to main content
2 of 7
added 576 characters in body
user avatar
user avatar

Here is an approach from a different angle. Don't do that :) I assume you want to re-load the asset because you want the original state?

What if instead of doing all that work just so you can reload the asset (which is comparatively expensive on some devices), you never modified the original load? Instead of just working with what you get from the Content Manager, make a Deep Copy and fiddle with that.

Some pseudo code here:

Destructible building1 = Content.Load<Destructible>("alphaBetaKappa.house").DeepCopy();

Now, DeepCopy would be an extension method you create that does just that. It creates a deep copy of the object and the unmodified one will always be cached.

This does have some downsides to it. To me, the most obvious one is if you forget to create the deep copy, you will have a bug that may or may not be hard to track down. But re-writing your own Content Manager could be just as risky and I would wager that it will take a bit of time to get it perfect.

Instead of re-inventing the wheel, why not just use the tools you have been given?


If you are still set on doing it, try something like this. Just overload the method telling it to cache or not. I pretty much snagged this from this blog, and he goes into more detail there. You might find it useful should you decide to go this way.

public override T Load<T>(string assetName)
{
    return Load<T>(assetName, true);
}

public T Load<T>(strng assetName, bool cache)
{
    if (loadedAssets.ContainsKey(assetName))
        return (T)loadedAssets[assetName];

    T asset = ReadAsset<T>(assetName, null);

    if(cache)
        loadedAssets.Add(assetName, asset);

    return asset;
}
user159