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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Can it be done: Export a ScriptableObject asset to be used in another project

Discussion in 'Editor & General Support' started by peabnuts123, Jan 27, 2018.

  1. peabnuts123

    peabnuts123

    Joined:
    Aug 8, 2013
    Posts:
    9
    Howdy all, I am creating an .asset file from a ScriptableObject I have storing some basic information:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class CompiledBuild : ScriptableObject
    4. {
    5.     public string[] WordStrings;
    6.     public Color[][] WordColors;
    7.     public int ChunkSizeMs;
    8.     public int FrameLengthChunks;
    9.     public int DownSampleFactor;
    10.     public string NetworkConfig;
    11. }
    The asset I am creating seems to be all good. I am creating these assets from an "Editor" project of mine and I intend to import these "CompiledBuild" assets into a separate "Game" project (the editor code is in no way needed to ship with the game so it is a separate project), however I am having trouble reading the .asset file within the main game project. I have this CompiledObject class in both projects (I have even tried placing them in exactly the same location in the project heirarchy) and they are identical, however it doesn't seem like Unity can read the exported asset if I paste it into the main game Project. If I have an object reference to a CompiledBuild object in the scene the Inspector shows there are no CompiledBuild assets, and if I click to drag the asset into the reference the text while dragging says "Nothing Selected" (the string hardcoded into Unity for missing script references).

    My question is this: Is sharing an .asset file between projects possible? Or are they tied to the project they were created in. I have also tried right-clicking my asset and choosing "Export Package", but the export window seems to want to include my entire project of script files as "dependencies" even though it is a pure ScriptableObject class.

    Is it possible? Or do I need to share my data differently? Any help much appreciated. I have searched around for this a fair amount online but cannot find anybody who is trying to share assets like this.
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    You're on the right track. You will need to export is as a custom package. In the export window you can select/deselect anything you want to be in the package. Be careful, you will want to include the asset file, the source file (the corresponding .cs file with the type in it).
    And you can simply import it in the other project. Feel free to deselect the project and select only the proper files in the export, you just need to know your exact dependencies.
     
    karl_jones and peabnuts123 like this.
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,419
    Is Unity finally able to de/serialize multi-dimensional arrays?
     
  4. peabnuts123

    peabnuts123

    Joined:
    Aug 8, 2013
    Posts:
    9
    Ah, it works! Interesting. I exported it with the CompiledBuild.cs file as well and it seemed to maintain the link after I imported it. I don't quite know how that works, but it seems to. Oh, maybe it links specifically to the GUID of the ScriptableObject? Perhaps I won't have to export it like that any more now that the GUID has updated. I will continue to investigate. This has definitely unblocked me now, thanks for your help!