Jump to content
  • Advertisement
Sign in to follow this  

[XNA] Default XML Values

This topic is 3049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, Is it possible to set up an XML to have default values for certain elements? What I am trying to do is add a new member to my base game object class. These objects are initialized by reading in XML data into a Definition class.
public class GameObjectDefinition
    // The position of the object in the world.  In the case of a 2D
    // element, the Z component will be ignored.
    public Vector3 mPosition = Vector3.Zero;
    // The pitch, yaw and roll of the object in the world.  In the case
    // of a 2D element, the rotation will be based around the Z axis (roll).
    public Vector3 mRotation = Vector3.Zero;

    // The scale of the object, with 1.0 being equal to it's original value.
    public float mScale = 1f;


    // The priority is used to decide what order the object is rendered.  Most of     
    // the time this can just use the default value.
    public int mRenderPriority = 100;
But I don't want to have to go through every existing XML file in my project and add the mRenderPriority element, just to assign it a default value. I'd like to just add it to the Game Object who want a value other than what I deem the default value. Is this possible? I get this error if I don't add it to any XML files:
Error	1	XML element "mRenderPriority" not found.
I load the XML data using the XNA Content Manager:
GameObjectDefinition definition = GameObjectManager.pInstance.pContentManager.Load<GameObjectDefinition>;(fileName);

Share this post

Link to post
Share on other sites
I haven't used IntermediateSerializer much, but it looks like if you add a ContentSerializerAttribute and set Optional to true it will skip over members that aren't found in the XML.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!