Indexing Content / LoadByID?

As my game (and it’s editor) gets bigger, I find myself moving asset files around quite often to try and keep things tidy and logical. I have a lot of assets, including json data files that refers to assets like this:

    "Name": "Bob",
    "Sprite": "/Heroes/Bob/BobSprite"

The problem is, if I move/rename the asset “/Heroes/Bob/BobSprite” to “/Graphics/Heroes/Bob”, this will break everything since the asset path changed and the file is no longer there.

For one file, it’s not too bad and I can go fix it manually but it becomes problematic when moving entire directories. To make things worse, I plan on releasing this editor to the public and I wouldn’t want to ship it in with this kind of issue.

Because of this I was toying with the idea of creating my own tool that would index these assets so that I could refer to them by GUID instead of by path.

    {"f3750b92-714a-11eb-9439-0242ac130002", "/Heroes/Bob/BobSprite"},
    {"d9eccbb5-bca7-4104-bef7-425119d42696", "/Graphics/Characters/Bob"}

The tool would keep track of file changes and update a Dictionary<Guid, string> so that I could in theory do something like Content.LoadByGUID(data.SpriteID). Since the GUID would be set in stone when the file is first added through the tool, the asset could be moved around without breaking the builds.

This could be quite a big change so I wanted to know your opinion on the matter before diving head first into this rabbit hole. Does it seem insane and/or am I re-inventing the wheel, not knowing this problem has been solved before?

Thanks in advance! :slight_smile:

I do something similar, I have an enum with all the files from my content.mgcb file. So all my loading goes through a static class fetching the “path” I dont have a tool auto updating this as I see this as a development thing so I can easy update all paths in one place if I move things around.

If this is good practice or not I don’t know… but if I’m doing it probably not :wink:

Ok, so first of all, you need this.

This automates the file referencing in mgcb.

Second, I’ve already made just the thing you need. There are no guids, since you don’t need them. It’s just a pipeline extension which catalogues all files in Content directory.

1 Like