Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to use AssetBundle's built in one project in a different project?

Discussion in 'Scripting' started by User340, Apr 30, 2017.

  1. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    I've read that it is possible to share AssetBundle's between different Unity projects. One thing I am unclear about is the scripts, how can I apply scripts onto prefabs and make sure they are applied properly when downloaded in the other project?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    You can't. You can't include scripts in asset bundles. Scripts have to be include in the project. So when your asset bundle is loading in for use, it can find the script and use it. Otherwise, if you delete the script and then try to use an asset bundle that uses that script, it doesn't work.

    I honestly don't know if you included the exact same script in both projects if it would work or not when building out asset bundles. I have not tried this.
     
  3. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Ok. Yeah I was thinking if that didn't work maybe if they were compiled into a DLL, maybe that would have more luck.

    I'm building prefabs that have scripts applied. I would like these prefabs to be in a separate project, because there so many of them.
     
  4. Tom-Goethals

    Tom-Goethals

    Joined:
    Mar 6, 2015
    Posts:
    102
    Hi Daniel,

    I'm about to embark on the same thing, splitting my project into multiple projects. Also have prefabs with code in the master and the "copy" project with the asset bundles. Have you had any luck making it work?
     
  5. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    I haven’t tried it yet. Currently have all prefabs in main project.
     
  6. Tom-Goethals

    Tom-Goethals

    Joined:
    Mar 6, 2015
    Posts:
    102
    just did it, seems to work fine.. made sure all meta files where copied along.
     
    LeandroExHuMeD likes this.
  7. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    So what did you do exactly? Did you just duplicate your main project? Any tips you can give on this topic will be greatly appreciated.
     
  8. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    Those meta files are crucial. If the meta files are missing, then the whole operation becomes sketchy as hell if Unity was to try to fix things up on its own.

    It's not enough to try to match script name to script name, because who knows if you'll have a same-named file in a new project, but implemented in a totally different way? (e.g. UI.cs or something like that).

    In fact, even with the meta files, I'm still not sure I'd trust the asset bundle integrity to be 100% intact unless you gave it a thorough test. If possible, I'd strongly recommend rebuilding it for the new project to be on the safe side, assuming you have access to the original assets.

    Put another way: Would you stake your reputation on this, and tell your manager that it's safe to use this asset bundle in a new project?
     
  9. LeandroExHuMeD

    LeandroExHuMeD

    Joined:
    Apr 6, 2016
    Posts:
    5
    it really works, thank you \o/
     
  10. EthanF4D

    EthanF4D

    Joined:
    Jan 9, 2018
    Posts:
    13
    For your interest, i am currently developing a project with a client.
    I split the project into two. One half is shared with the client filled with their art assets together with scripts that compose the game logic. The other half is not disclosed. It manages the multiplayer related stuffs and load asset bundles produced from the first half.

    The game logic scripts derived from MonoBehaviour and their meta has to be present in both projects. BUT the script is allowed to have totally different implementations.
    Code (CSharp):
    1. // in both halves
    2. public class Spawner : MonoBehaviour
    3. {
    4.   public void Spawn(string prefabId)
    5.   {
    6.     SpawnerImpl.Spawn(prefabId);
    7.   }
    8. }
    Code (CSharp):
    1. // in shared half, no multiplayer feature
    2. public static class SpawnerImpl
    3. {
    4.   public static void Spawn(string prefabId)
    5.   {
    6.     Debug.Log(“no multiplayer”);
    7.   }
    8. }
    Code (CSharp):
    1. //in non disclosed half
    2. public static class SpawnerImpl
    3. {
    4.   public static void Spawn(string prefabId)
    5.   {
    6.     Debug.Log(“with multiplayer”);
    7.   }
    8. }
    9.  
     
  11. mabulous

    mabulous

    Joined:
    Jan 4, 2013
    Posts:
    198
    How would it deserialize serialized fields if the implementation is different?