This has probably been asked before, but I couldn’t find any threads that addressed my problem exactly, so sorry if it’s a double post.
My project needs to store instances of a custom class called Area inside binary files, which are serialized by implementing the ISerializable interface.
This is being done with no problems, and I can end up having an *.area file with the results.
The problem comes when I try to stick it into an AssetBundle.
Selection.activeObject returns the selected Area objects with no problems (even though they don’t derive from Object), but when I use BuildPipeline.BuildAssetBundle() with that selection, I end up with an empty AssetBundle.
I realize that this is a custom file type and that might mess things up, but how would I go around this problem? Or more specifically, what IS the problem here?
Thanks cannon! I tried your suggestion by changing the “.area” extension to “.xml”, but even though Unity seems to properly recognize it as a TextAsset, it still doesn’t export it to an AssetBundle.
Here’s the code I’m using to serialize my custom Area assets:
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(destinationPath + areaAsset.name + ".xml", FileMode.Create, FileAccess.Write);
formatter.Serialize(stream, area);
stream.Close();
And this is how I’m trying to export them to an AssetBundle:
you import it correctly into the project before you build (if you build right after writting its potentially not “there yet” so you can not refer to it for building)
you close the file from serializing it before leaving? (guess thats a given but checking is always better)
As for 2), I would think so, because I’m selecting the file to export from the project view. I think I even tried to export it after closing and reopening the project. But then again, maybe it’s not properly imported?
I’m suspecting this might have something to do so I’ll run some tests tomorrow. But just to make sure, what would be the “correct” way of importing an Asset created with the serialization code I posted above?
I think I might have got it. According to the docs, Selection.GetFiltered doesn’t allow the DeepAssets selection mode unless the filter type is derived from GameObject or Component. Since you’re using Object as the type, the call is probably just silently returning an empty selection.
i think you should check if your codes first line returns anything or not and i think you should trying selectiong with filtering and see if work or not?
i mean dont use Selection.GetFiltered and instead select the txt file with mouse and use Selection.ActiveObject without filtering and see if works or not
Asset bundles have nothing to do with your file type they just get them compress and encrypt them and package them to a file.
they are a very powerful feature i love them much but i just used them in unity pro’s trial version
asset bundles have a lot to do with file types.
Source code for example can not be put into asset bundles, it will be killed (all code must be in the app or does not exist)
asset bundles can store code but they compile the code and store them. you can create asset bundles with complete scenes or new objects with new scripts.
i meant that asset bundles can store any type of files in themselves and i think they do just what they should do. they create bundles just like exe files and new type of resources can be added easily
there is nothing special about an asset bundle.
however i think someone like joe can answer this question well but i think that he is not on the forums
I actually checked what Selection.GetFiltered() was returning and it does look ok, all the selected objects are there. I should have mentioned this, my bad.
As for the file types, I’m not sure that is the problem. I tried storing the binary files as TextAssets by renaming them to either .txt and .xml, and it did import them OK (I got garbage on the inspector of course, but it was there). However, it didn’t work either.
Also, I’m using Unity iPhone Advanced v1.5.0f3. Haven’t tried with 1.5.1b1 yet (I understand AssetBundles have been fixed).