Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Adding Custom Data to AssetBundle

Discussion in 'Scripting' started by dave_mm0, May 15, 2020.

  1. dave_mm0

    dave_mm0

    Joined:
    Feb 8, 2013
    Posts:
    26
    Hey!
    So I'm trying to find a way to allow users to create custom content for my game, using Unity as the editor for this content. So far, it works pretty well, using AssetBundles.
    Now I want certain gameObjects in the level to be have data on it. No script, only data. For example, I would want a cube to have a "score" value.
    I can't add a MonoBehaviour to it, because then my game won't load the bundle, since you can't have scripts in there.
    I tried serializing the data into a json file, but then it looks like I can't include the TextAsset in the same AssetBundle as my level, I get the following error:
    "Cannot mark assets and scenes in one AssetBundle. AssetBundle name is "samplescene"."

    So now I'm a bit stuck. Any ideas on how I can move forward? Thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    This only means you can have an asset bundle without scenes, or if you put even ONE scene into an asset bundle, you cannot have anything scenes in that asset bundle.

    You can certainly mark pretty much any asset for inclusion in an AssetBundle, but you would need code to load it and insert it wherever you need. There's some tutorials about it.

    Here is a relevant post:

    https://forum.unity.com/threads/mixing-scenes-and-other-assets-in-asset-bundles.567091/
     
    Last edited: May 15, 2020
  3. dave_mm0

    dave_mm0

    Joined:
    Feb 8, 2013
    Posts:
    26
    Thanks Kurt, but that's the thing, I'd like these to be in a single assetbundle, so that users don't have to load multiple files. I worked ym way around it by including a script in the AssetBundle...I don't like it, but whatchya gonna do!
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
  5. dave_mm0

    dave_mm0

    Joined:
    Feb 8, 2013
    Posts:
    26
    Interestingly enough, it is a C# script and it works fine, as long as compiler versions are the same. Also, It's only data, so a list of public variables that the main game reads in... Not gorgeous, but it works fnie.
    Here's a video of it!
    Actually, I'm wondering if ECS would've been a good choice here, because that's essentially what the main game is doing, just not very efficiently