Versioning for Content files

Hi,

I am wondering if there is any support for file versioning at all in the Content Pipeline? If not, how do people generally handle this very common issue during development?

Example of the issue:

In version 1 of your Actor data file (xml file), you have the following setup:

   public class Actor
    {
        public string Name { get; set; };
        public int Layer { get; set; };
        public string TexturePath { get; set; }
    }

In version 2, you have this:

   public class Actor
    {
        public string Name { get; set; };
        public string TexturePath { get; set; }
    }

This will cause the existing file (containing the removed Layer property) to fail building via the Content Pipeline. What would you usually do in this scenario? Manually edit all the actor XML files? Setting the optional property on the properties doesn’t seem to help.

Is there a development step that I am missing that loads the xml files as dictionaries (order independent)?

Thanks!

1 Like

Hi @apan_apansson, Welcome to the Forums!

Some platforms have specific behaviours, which are you developing for?

Have you considered using GitHub for version control?

Other than the above, others may tune in with alternative local options.

Look into Version Control Software in the meantime.

Happy Coding!

Sure, that’s the apparent option. It just amazes me that this hasn’t been brought up anywhere. Or perhaps I should be amazed about my bad google skills :stuck_out_tongue:

I think you are misunderstanding me. I am not talking about version control for my code, rather versioning regarding my data. So that if you update your data structures (my content), like in my example above, you’d still be able to solve this in code without needing to update all your assets to match the expected syntax.

For example, you could use a lookup approach where you search for the data that your class expects (in my example the Actor class) and if it exists in the data, you’d use it, if not, you skip it or give it a default value. I naively assumed the reflection system could handle this, but the way it’s used in the Content pipeline, it is both order and memory alignment dependent.

Hmm :thinking:

So you want deprecated assets to be added regardless of states?

Hopefully someone with more experience can chime in…

Well, I wouldn’t call them deprecated, rather modified or iterated. It’s not a biggie, I can implement a dev version of the xml importer myself, I was just curious if there is already something in place that I could use.

Normally, I would use text formatted assets as much as possible during development to work around this issue and use optimized binary files for the package game.

Wouldn’t one just iterate the folder on launch?

Just asking the silly questions for anyone not sure…

I think I know what you are trying to do. In my case I use a combination of serialization and data contracts with data members

using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;

for example:
I define my classes as dataContract as follows

[DataContract( Name = “GenericControl” , IsReference = true )]
public Class whateverYourClassIs
[DataMember] public static int touchAccuracy = 25;
[DataMember] public bool isFrozen = false;

every variable I want to store I define them as data members
and through serialization I save my whole class as a file, I can load every single thing from there without problems.

The magic that really happens later is if you add/remove members the serialization load/save will still work on the old files, I created old files and when loading them , even if the fields do not exists or new ones are added, it will still load, if the members that do not exists in the old file are found, those will take the default values defined in the default part of your class. All the removed ones will be ignored in the new version. So it enables me to save tons of things and iterate on the fly, but this doesn’t run in the content manager, it works outside.

I prefer this way since I can put a lot of code/classes outside my main game, and re-use those in another games. For example, I am making my whole UI interface a generic file that I can add to any of my games, new or removed fields of that UI for each game can be added or removed without me having to create a new UI. I want to spend as little time on basic things on each game that repeat themselves, main menu is one of them with all the screen and control config settings.

Hope this helps.

Yup, that looks just about it.

I actually tried creating my actors as json and parsing them with Text.Json in a custom content importer/writer/reader and so far so good. The reflection system in there doesn’t explode on every modification, but instead seems to skip properties it can’t find.

A bit more work, but a bliss to not have to keep your files exactly as expected by the serialization. I can also include versioning easily, so in case things do explode, I can solve issues in code rather than having to fix all assets.

Thanks for the tips!