Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

[Urgent] Exported swf 4 bytes big

Discussion in 'Flash' started by Super Flat, Jul 29, 2012.

  1. Super Flat

    Super Flat

    Joined:
    Jul 9, 2012
    Posts:
    16
    I'm busy wrapping up a project and i have 11 scenes in my game. My interface is done in Flash and i'm loading my game swf in.
    The way i'm managing the scenes is with a Loading Scene in the unity swf which is empty but has a controller to load the right scene. So now i've added all 11 scenes to the project and trying to export it to a swf but the resulting swf ends up being 4 bytes big and no error thrown!

    Having removed scenes 1 at a time I find that i can't add the last two scenes. File size was already past the 500mb at this point.

    How can i solve this?
     
  2. catburton

    catburton

    Joined:
    Mar 29, 2011
    Posts:
    43
    Try having each of your scenes exported to an asset bundle and loaded at runtime so that your main swf is smaller.
     
  3. Super Flat

    Super Flat

    Joined:
    Jul 9, 2012
    Posts:
    16
    Hmm, how do you recon i go about creating and loading them? I don't have mu experience with asset bundles. Let alone converting that to flash

    [Edit] Just found streamedScene assetbundles. Sounds like that will do the trick!

    [Edit 2] Hmm.. Can i use www to load local files in flash??
     
    Last edited: Aug 7, 2012
  4. catburton

    catburton

    Joined:
    Mar 29, 2011
    Posts:
    43
  5. Super Flat

    Super Flat

    Joined:
    Jul 9, 2012
    Posts:
    16
    Aye, i got all that setup but since i'm exporting to flash Application.path and such aren't available and WWW needs file:// to get the local file. Do you know if there is a way to get a relative path in there?
     
    Last edited: Aug 7, 2012
  6. catburton

    catburton

    Joined:
    Mar 29, 2011
    Posts:
    43
    Try getting the path relative to your main swf, e.g.:

    Code (csharp):
    1.  
    2. if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.WindowsEditor)
    3.     download = new WWW ("file://" + Application.dataPath + "/../AssetBundles/Shared.swf");
    4. else if(Application.platform == RuntimePlatform.FlashPlayer)
    5.     download = new WWW ("./AssetBundles/Shared.swf");
    6.  
     
  7. Super Flat

    Super Flat

    Joined:
    Jul 9, 2012
    Posts:
    16
    Hmm following what's in the docs and what you posted above the code looks like this:
    Code (csharp):
    1. IEnumerator Start()
    2.     {
    3.         /*Object[] loaders = FindObjectsOfType(typeof(Loader));
    4.         if(loaders.Length > 1)
    5.             DestroyImmediate( gameObject );*/
    6.        
    7.         string path = "";
    8.         #if UNITY_EDITOR
    9.         path = "file://" + Application.dataPath + "/../AssetBundles/tuls.unity3d";
    10.         #else
    11.         path = "tuls.unity3d";
    12.         #endif
    13.  
    14.         WWW www = WWW.LoadFromCacheOrDownload( path, 5 );
    15.        
    16.         yield return www;
    17.        
    18.         if(www.error != null)
    19.             Debug.Log( www.error );
    20.         else
    21.             Debug.Log( "succes" );
    22.        
    23.         AssetBundle bundle = www.assetBundle;
    24.     }
    But when i try to load a level Unity will crash:

    Code (csharp):
    1. Application.LoadLevel( "Dan Gun" )
    [Edit] Just dawned on me that i'm trying to load a flash assetbundle; Trying with a webplayer one
    [Edit2] Yup! That was the culprit. It works in the editor now. Time for some flash.
     
    Last edited: Aug 7, 2012
  8. catburton

    catburton

    Joined:
    Mar 29, 2011
    Posts:
    43
    Here's a very quick/basic example project which shows how asset bundles work for Flash export. I've included in the project some example source to build and load the asset bundle.

    If you run BaseScene.html in the BuiltExample folder and click the GUI button, that will load the bundled scene.

    View attachment $AssetBundles-Scenes.zip
     
  9. Super Flat

    Super Flat

    Joined:
    Jul 9, 2012
    Posts:
    16
    I'm assuming i need to rename .unity3d to .swf then?

    [Edit] Seemed to be the case. Thanks Cat!
     
    Last edited: Aug 7, 2012
  10. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    No, the assetbundles can have any extension; they are not swf files.
     
  11. Super Flat

    Super Flat

    Joined:
    Jul 9, 2012
    Posts:
    16
    I see. At any rate i can load asset bundles now, but there seems to be a size limit. Loading an assetbundle over 200mb times out in flash.
     
  12. munnaz1

    munnaz1

    Joined:
    Jul 31, 2012
    Posts:
    1
    Hi there.
    thanks so much for your demo files cat.
    problem is i can load the swf at runtime but how do i go about exporting the bundledScene script in the first place?
    in the example if i change the paths within ExportSceneBundles.cs (to build/) and build the project it does not re-export the swfs into that location...
    thanks for any help
    b
     
  13. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    that will be no problem in reality. Cause users will have closed and cursed your games long before that happens as 200mb takes eternities to download every time again



    Those are two different things.
    BundleScene creates streaming scenes, they are not flash players nor are they even able to do somehting on their own (they contain no code or shaders).
    You still need to build a normal flash build that has the code and 'core project' in to load these scenes etc
     
    Last edited: Aug 13, 2012
  14. frevd

    frevd

    Joined:
    Aug 29, 2013
    Posts:
    8
    For anybody who has the same issue - for me it was the RAM. I had deactivated the paging file in Windows and the out-of-memory error seems to be silently ignored by the flash exporter. Adding more RAM (resp. increasing the page file) solved the problem.