- Home /
Exclude code from SWF
Hi,
I'm new to Unity and I'm using the Flash export. I want to have 1 swf file per level of my game.
When I look at the list of exported classes in the swf, I can see a lot of classes in the packages global, System and UnityEngine. I understand that those classes are required for the game to run.
I want to load these classes only once, but they are included on every swf that I export. Is it possible to avoid this waste of file weight?
Answer by catburton · Jun 19, 2012 at 03:56 PM
If you wish to save file-size of your bundled scenes, you can use streamed scenes with push/pop dependencies to achieve this.
Build a player from your main scene.
Push dependencies
Build any additional streamed scenes
Pop dependencies
This will result in your main scene swf being its usual size but your streamed scene swfs will be much smaller.
Here's a quick example that you should be able to modify for your project:
public class ExportSceneBundles : Editor
{
[MenuItem("Assets/Export Scene Bundles")]
public static void Export()
{
System.IO.Directory.CreateDirectory("SceneAssetBundles");
var options = BuildAssetBundleOptions.CompleteAssets;
BuildPipeline.BuildPlayer(new string[]{"Assets/BaseScene.unity"}, "SceneAssetBundles/BaseScene.swf", BuildTarget.FlashPlayer, BuildOptions.None);
BuildPipeline.PushAssetDependencies();
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildStreamedSceneAssetBundle(new string[]{"Assets/StreamedScene.unity"}, "SceneAssetBundles/StreamedScene.swf", BuildTarget.FlashPlayer);
BuildPipeline.PopAssetDependencies();
BuildPipeline.PopAssetDependencies();
}
}
Hi Cat,
Thanks a lot for your reply. We did use the asset bundles at some point, like you suggest in your response. But in the end, we used another approach for our project.
When making a project for Flash with Unity (we are using 3.5 right now) it's not a good idea to output multiple swf for the same project. You will end up with lots of duplicated stuff. It's a better idea to place all scenes inside of only 1 swf. For us, it was a big improvement. We used to have 25 swf 4$$anonymous$$b each (1 per level). Now, we are packaging all level together (1 level = 1 scene) and we have only 1 swf of 8$$anonymous$$b. So yeah, there had a lots of duplicated stuff!
Also, to improve the loading time, we start the Unity's swf downloading while the user is browsing the menus.
$$anonymous$$aybe there are even better practices for flash projects in Unity, but we didn't found them yet. Any comment/suggestion is welcome!
Hi Cat,
Thanks a lot for your reply. We did use the asset bundles at some point, like you suggest in your response. But in the end, we used another approach that we better for our project.
When making a project for Flash with Unity (we are using 3.5 right now) it's not a good idea to output multiple swf for the same project. You will end up with lots of duplicated stuff. It's a better idea to place all scenes inside of only 1 swf. For us, it was a big improvement. We used to have 25 swf 4$$anonymous$$b each (1 per level). Now, we are packaging all level together (1 level = 1 scene) and we have only 1 swf of 8$$anonymous$$b. So yeah, there had a lots of duplicated stuff!
Also, to improve the loading time, we start the Unity's swf downloading while the user is browsing the menus.
@DDP: Don't post comments as answers. If you want to reply to a post, use the "add new comment" button below the post. If you want to answer your own question, post an answer, but only if it's intention is to answer the question.
Since you already accepted catburton's answer i guess it solved your problem.
@DDP - I'd be interested to know what was duplicated in each of your scenes to result in each swf being 4$$anonymous$$B in size. Perhaps if they are all sharing some common assets, which could be bundled into a shared asset bundle. It sounds like your solution worked well for your project, but if you did want to use the asset bundles, let me know and I'll try to help you work out why they were so large in size.
Your answer

Follow this Question
Related Questions
Flash raw animation data to Unity 0 Answers
Reduce AI processor weight 2 Answers
Unity large level size in build 0 Answers
Optimization unity flash 1 Answer