6
\$\begingroup\$

Let's say I have an xml file which looks like this

<Weapons>
 <Weapon>
  <Name>Pistol</Name>
  ...
 </Weapon>
 <Weapon>
  <Name>MachineGun</Name>
  ...
 </Weapon>
</Weapons>

Would it be possible to use a custom importer/writer/reader to create two files, Pistol.xnb and MachineGun.xnb which I can load individually with Content.Load()?

While writing this I realized I could just import a Weapon[] list and split them up with a helper, but I'm still wondering if this is possible?

\$\endgroup\$
4
\$\begingroup\$

Basically: No.

The content pipeline transforms a single input file into a single output file. It can also do a single input file plus dependencies, into a single output file. And you can also trigger building of other files into assets.

But it cannot generate multiple outputs from a single file.

This thread on the App Hub forums explains it in more detail. (And may have some ideas for work-arounds.)

\$\endgroup\$
  • \$\begingroup\$ link has decayed \$\endgroup\$ – Andrey Sep 4 '12 at 3:37
7
\$\begingroup\$

Yes, you can.

With the dependency system, you can call

ContentProcessorContext.BuildAsset
ContentProcessorContext.BuildAndLoadAsset

to make the Content Pipeline build whichever asset you want, and get the external reference to that file. Keep in mind that this isn't very flexible, and all the assets built this way will have the name of the original asset plus "_0", "_1", etc. to mark them as dependent from the original.

Also, ContentProcessorContext is an abstract class and you can inherit from it and extend with the functionality you want. So, when you are compiling your specific asset, create a new instance of your custom processor context and let it do its own magic.

Keep in mind that this requires a very advanced knowledge of the XNA pipeline and will be too much effort if you are a beginner.

\$\endgroup\$
  • \$\begingroup\$ Even though this technically is a more correct answer, Andrew's was still more the answer I was looking for. \$\endgroup\$ – Zeta Two Mar 28 '11 at 16:35
  • 5
    \$\begingroup\$ Then if you are expecting a "no", I don't see the point in asking :) \$\endgroup\$ – r2d2rigo Mar 28 '11 at 18:05
  • \$\begingroup\$ If you call the second overload of BuildAsset() you will even be able to specify the name of the output asset. \$\endgroup\$ – cubrman Mar 29 '15 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.