- Home /
Why isn't my scriptable object storing correctly in the AssetBundle?
I want to make AssetBundles which include two textures and two colours. The colours are stored in a custom C# class declared as follows:
public class PaintInfo : ScriptableObject
{
public Color primary;
public Color secondary;
}
while the C# code used to build the bundle looks like this (with diffuseTex and specularTex both being Texture2D objects). The colours are hard-coded for now, but will eventually be sourced from elsewhere.
diffuseTex.name = "Diffuse";
specularTex.name = "Specular";
string outputName = "TEST.UNITY3D"
PaintInfo newPaintInfo = ScriptableObject.CreateInstance<PaintInfo>();
newPaintInfo.name = "PaintInfo";
newPaintInfo.primary = new Color(1.0f, 1.0f, 0.0f, 1.0f);
newPaintInfo.secondary = new Color(1.0f, 0.0f, 0.0f, 1.0f);
// save the asset to be able to put it in the asset bundle
string assetName = "TEST_PAINTINFO.ASSET";
AssetDatabase.DeleteAsset(assetName);
AssetDatabase.CreateAsset(newPaintInfo, assetName);
AssetDatabase.SaveAssets();
List<UnityEngine.Object> texList = new List<UnityEngine.Object>(EditorUtility.CollectDependencies(new UnityEngine.Object[] { newPaintInfo }));
texList.Add(diffuseTex);
texList.Add(specularTex);
bool buildOk = BuildPipeline.BuildAssetBundle(null, texList.ToArray(), outputName, BuildAssetBundleOptions.CollectDependencies);
if (buildOk)
{
logFile.WriteLine("# Bundle created ok");
}
else
{
logFile.WriteLine("# Error: Bundle not created");
}
When I load in the asset bundle in the game code, the two textures are correctly present, but instead of the PaintInfo object, I have a TextAsset whose name and text fields are both empty strings. What am I doing wrong?
Your answer
Follow this Question
Related Questions
Using ScriptableObject with Asset Bundles 1 Answer
How to import the object from server to unity 2 Answers
Shader References seem broken for AssetBundle in HDRP Project 1 Answer
How do I pass serialized ScriptableObjects between Unity projects? 2 Answers
How to download XRReferenceImageLibrary From Asset Bundle in AR Foundation 2 Answers