In-Game Resource Management (How to?)


recently I’ve been working on the resource manager for my RTS game. I had looked on the internet for ideas and I found a way using Resource folder. It looks really easy and simple, but my only concern is safety. What if the user deletes the file or modifies it in some way. The asset file will be corrupted or will not be loaded because it does not exist anymore. That would break the game, if for example curtain unit could not be loaded. Or do I understand something wrong about this?

The thing I use now is Scriptable objects. I have two types of scriptable objects: “RecourceManager” and “Asset”. The “Asset” is just a name of the object and a gameObject prefab reference. Inside the “RecourceManager” I have a list of “Asset” objects and everytime I want to get a reference of an object I call a function and pass a name of object I want to receive. Then inside that function I loop through all the assets list and check if the name I passed exists in the list of “Asset” objects. If so I return the prefab reference.

This way works fine, but the only downside is that I have to reference the “RecourceManager” everytime.

Is this even a good way of making something like this or are there any better ways?

Thank you!

The Resources folder will not exist in the game build. The only thing it does is protecting all the assets in it against build stripping, and making them available via Resources.Load. But assets in it are packed into asset files like all other assets. And if a user deletes or modifies one of those and the game stops working, it’s really not your fault.

Concerning the approach - in my opinion, the Resources folder is extremely overused. It’s nice to have if you need control over when exactly an asset is loaded or unladed, but people use it all the time without that need.

Instead of using the Resources folder, consider simply dragging things into fields of your MonoBehaviours. If you have a prefab, simply make a field of type GameObject, or even make the type a component the prefab must have. Then drag the prefab into your component using the inspector. Same goes for ScriptableObjects. Just make a field of whose type is your ScriptableObject-derived class and drag the object into it. The prefabs or ScriptableObjects will have been loaded before you use it.