XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

BuildAndLoadAsset behaviour?

Last post 8/30/2009 5:47 PM by Shawn Hargreaves. 5 replies.
  • 8/28/2009 10:41 PM

    BuildAndLoadAsset behaviour?

    What happens if I call BuildAndLoadAsset on the same file several times? Will it re-build the asset each time or will it just do it the first time and subsequent calls use a cached version?

    I suspect it rebuilds it several times, is there any way to get the later behaviour? I need to build one asset first and use the result for building a series of other assets, is this possible?
  • 8/29/2009 1:14 AM In reply to

    Re: BuildAndLoadAsset behaviour?

    I believe if all the parameters to BuildAndLoadAsset are identical, it will reuse the previous build output. If the parameters are different it will be rebuilt every time. It attempts to cache the intermediate output from a build, so a change to one of the files you're building with BuildAndLoadAsset will not cause the rest to be rebuilt.
    Kevin Gadd, Squared Interactive
    Development Blog | Twitter
    Help playtest my game, Inferus!
  • 8/29/2009 12:08 PM In reply to

    Re: BuildAndLoadAsset behaviour?

    Huzzah! That's great, I wrote a little test pipeline to test this and as you say it does indeed cache the output which is awesome! However, it does seem to build things twice if I use BuildAndLoadAsset as well as having that asset in my content project. That's not a massive problem for me, I just wanted to avoid it being built once for each asset that references it, which could be hundreds of times.
  • 8/30/2009 12:45 AM In reply to

    Re: BuildAndLoadAsset behaviour?

    If you already have the asset in question in the content project, I believe you can just use context.AddDependency to tell the content pipeline that your resource is dependent on that resource, and then in your asset loader (at runtime), when your resource is being loaded from an XNB, load the XNBs that you're dependent on as well.
    Kevin Gadd, Squared Interactive
    Development Blog | Twitter
    Help playtest my game, Inferus!
  • 8/30/2009 8:59 AM In reply to

    Re: BuildAndLoadAsset behaviour?

    That does not seem to work. My understanding of the context.AddDependency is to inform the build system that if any changes occur in the file referred to in the AddDependency call then it must rebuild the current asset being built.
  • 8/30/2009 5:47 PM In reply to

    Re: BuildAndLoadAsset behaviour?

    Exactly right. AddDependency is for telling the pipeline about additional work that you did, so it can do the right thing when considering subsequent rebuilds. This doesn't actually do any work itself other than tracking the supplied filename and timestamp of that file.

    If a file is both in your content project directly and also read using BuildAndLoadAsset, this will normally get imported just once, and the importer results cached in the intermediate directory. The request coming from the content project will then cause this cached data to be deserialised, run through the processor, and the outputs written to the final output folder. The request(s) coming from BuildAndLoadAsset will then cause the cached data to be processed a second time, and the processed results cached back in th intermediate folder, from where it can be deserialized as many times as are required by BuildAndLoadAsset calls. So you will typically see the importer run just once (unless this particular importer specifies CacheImportedData = false), but the processor will run twice.

    There's obviously room for us to be smarter about this particular scenario, but it didn't seem an important thing to optimize for since it's quite rare you would want the same asset built using the same processor, but one copy sent directly to the output folder and a second copy of that same data embedded inside some other asset. Most commonly files referenced using BuildAndLoadAsset will not also be built directly to the final output folder.
    XNA Framework Developer - blog - homepage
Page 1 of 1 (6 items) Previous Next