Manage model modding

Good day,

I wanted to implement a system which will allow users to add models of certain characters into my game, these characters have also data associated with them (like names). My problem isn’t the code but consistent format. I currently have two models (and their respective data), which I wish to convert into a single file “mod character” (for each character), I want to take a model, take class data, and put them into a single file, and once I start the game, I would load that file, add that class to a List<> and assign model to class in that list. So that if someone were to create a character and drag a single file into mods folder, it would be read and the character would be added by the game.

Long story short, what is a consistent way I could encode/decode the character and its attached data? Preferably I wouldn’t put raw files and raw class text file.

P.S.: Every setting needs to stay the same, the material settings, the texture settings.

Edit: Essentially I’m looking for a way to convert a Hierarchy GameObject (one I can see in the Inspector) into a transportable binary string which then can be converted back into a GameObject. The way I can do with images, this way I can do whatever I want with it. I can set rotation and position by myself (through scripting). I thought about Export/Import package, but I think don’t know how to handle it programatically.

Sounds like an asset bundle with a prefab inside?

Can that be written and read at compiled run-time?

Only read. You need to build bundles for specific platforms before use with unity asset bundle build pipeline.

I belive you might send the model and other files you want to include in a bundle to your build server from compiled build runtime and download ready to use bundle as soon as it ready on server side. I would try this way because others are mess with zip files and a bunch of runtime importers plugins from third party developers not neccessary compatible with each other.

1 Like

Can a modder install Unity, make a bundle conforming my stipulations, and could I read it afterwards and import it into my game? Or do I/they still need that “render pipeline server”?

No, this server is not required. Modder of course can install Unity, make mods and build that bundle itself. Moreover, you can provide modders with additional assets and scripts to make modding and building a bundle process easier for them. I proposed you to work with build server only because you asked how to build a bundle from runtime player. If your modders can install unity and build bundles themselves, then this is not needed.

I tried building a package but something went wrong, with this code:

#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class BundleRenderer : MonoBehaviour
{
    [MenuItem("Assets/BuildVanilla")]
    static void whateveriwant()
    {
        BuildPipeline.BuildAssetBundles("Assets/MYOUTPUT", BuildAssetBundleOptions.None, BuildTarget.NoTarget);
    }
}
#endif

This error has been shown:

UnityEditor.BuildPipeline:BuildAssetBundles(String, BuildAssetBundleOptions, BuildTarget)

Am I going the right way about this?

Yes, but you need to specify target platform for the bundle. You need to build different bundles for different target platforms. You’d better start with installing asset bundle browser package, it has nice UI for building bundles and it;s code is good as example to learn and use.

Why? Why can’t I convert models/images/textures into binary file the same way I can do with images? How do other games do this when you just need to download one file which fits all platforms, and it contains everything you need? What is so different about Unity?

I see. Still I’d rather automate it for my modders so I can automatically render all the required packages and just drop a ready file. Anyways, I got it working, but weirdly enough it creates four files.

Two based on the folder name “myfolder” and “myfolder.manifesto”. “myfolder” is 1kB and contains item “AssetBundleManifest”, “myfolder.manifesto” is 1kB and throws upon read.

Two based on the actual mod name “mod” and “mod.manifesto”, after some trial and error I found out that “mod” file works and is what I’m looking for. “mod.manifesto” also throws upon read.

What does manifesto contain in that scenario? Aren’t manifesto’s required for an application to understand how to unpackage data? Does .manifesto hold data regarding UAC and certification or something?

Why generate “mod.manifesto” file, why generate “myfolder” file and it’s manifesto; and what do I need “AssetBundleManifest” for, if I already have “mod” file that contains all the data I need?

Thanks.

Edit: If they’re not needed that badly, is it possible to tell Unity (through code), to generate just that one single file?
Edit2: Well, .manifest contains metadata which are seemingly unneeded.
Edti3: Turns out manifesto is needed for caching (so you can load something from cache instead of redownloading from the Internet).

Data in asset bundle is optimized differently for every platform. When you loading same png on iphone and android it is decoded to platform native format and then loaded into video memory. Texture in bundle is already optimized for plaform.

Manifest contain asset list and references. You don’t need it because all assets from mod going into one bundle. But it is common to use manifests. For instance, I have bundle named DialogIcons and I have every in-game dialog in separate bundle. All those bundles have reference to DialogIcons.

File named after folder contains manifest describing all references beween bundles. Also manifest contains checksum to verify bundle integrity and that’s why it can not be embedded into the bundle file itself

It was possible in previous version API but this feature where removed. Idk why.

This manual section helped me alot https://docs.unity3d.com/Manual/AssetBundlesIntro.html