Search Unity

Unity 4.0.0f7 loadUnity/unloadUnity Problem

Discussion in 'Flash' started by vbiancardi, Nov 30, 2012.

  1. vbiancardi

    vbiancardi

    Joined:
    Oct 5, 2012
    Posts:
    6
    On first init everything loads fine and there are no problems. It hits shutdown and I do:

    Code (csharp):
    1. mUnityLoader.unityContent.setContentHost(null);
    2.             removeChild(mUnityLoader);
    3.             mUnityLoader.unload();
    4.             mUnityLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onUnityContentLoaderComplete);
    5.             mUnityLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onUnityContentLoaderProgress);
    6.             mUnityLoader = null;
    7.  
    Then when I hit the init again I do:
    Code (csharp):
    1.  
    2. var params:UnityLoaderParams = new UnityLoaderParams(false, width, height, false);
    3.             mUnityLoader = new UnityContentLoader(UnityFileUtility.getSWFPath() + swfName, this, params, false);
    4.             mUnityLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onUnityContentLoaderComplete, false, 0, true);
    5.             mUnityLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onUnityContentLoaderProgress, false, 0, true);
    6.             mUnityLoader.loadUnity();
    7.  
    On this second pass it breaks before the load completes and I get this:

    TypeError: Error #1034: Type Coercion failed: cannot convert System::ClassType@19da38c9 to System.Type.
    at System::Type$/ForClass()
    at System::CLIByteArray/CLIByteArray_Constructor_Vector$1_ByteArray()
    at System::CLIArrayFactory$/NewByteArrayWithLength()
    at System.Text::ASCIIEncoding/Encoding_GetBytes_String()
    at UnityEngine::WWWTranscoder$cinit()
    at global$init()
    at UnityEngineClassIndex$/InitializeClasses()
    at com.unity::UnityNative$/init_actionscript_cctors()
    at com.unity::UnityNative$/Native_Init()
    at com.unity::UnityContentInternal/initNativeEnvironment()
    at com.unity::UnityContent/onFrameInitStep()

    Any suggestions?
     
  2. vbiancardi

    vbiancardi

    Joined:
    Oct 5, 2012
    Posts:
    6
    I tried to not unload, and just keep the unityContent around as a static variable as a work around; however, when my component gets initialized for the second time I cannot call startFrameLoop or else I will get a null error in InputHelper enable().
     
  3. jimboloo

    jimboloo

    Joined:
    Feb 13, 2013
    Posts:
    1
    :( I get the same error if I load a unity swf and then load another one at a later time somewhere else in my application.

    It seems if you unload and then reload OR don't unload try and load more than one unity swf you get this error:

    TypeError: Error #1034: Type Coercion failed: cannot convert System::ClassType@df0a511 to System.Type.
    at System::Type$/ForClass()
    at System::CLIByteArray/CLIByteArray_Constructor_Vector$1_ByteArray()
    at System::CLIArrayFactory$/NewByteArrayWithLength()
    at System.Text::ASCIIEncoding/Encoding_GetBytes_String()
    at UnityEngine::WWWTranscoder$cinit()
    at global$init():(:(:(:(
     
  4. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,279
    Yes we just came across this same issue - perhaps submit a bug report?

    On a side note - the fact the 2-3mb unity runtime portion can not be shared between multiple swfs at present makes having more than one unity-swf a bit download-heavy so loading assetbundles might be better.
     
  5. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    Please submit a bug with a repro case.
     
  6. Azis

    Azis

    Joined:
    Aug 1, 2012
    Posts:
    4
    I have been facing this problem for every version newer than Beta 12. I have sent some bug reports, but no fix has come out yet.

    A workaround you can do is, instead of using UnityContentLoader.loadUnity, calling

    Code (csharp):
    1. var ctx : LoaderContext = new LoaderContext(false, new ApplicationDomain());
    2. yourUnityContentLoader.load(new URLRequest("swfPath.swf"), ctx);
    However, you will get many class conversion problems. For instance, your IUnityContentHost classes won't be recognized anymore.
     
    Last edited: Apr 15, 2013
  7. Tomek Loeb

    Tomek Loeb

    Joined:
    Aug 13, 2012
    Posts:
    7
    Any news on this? Unfortunately Azis' workaround didn't work for us, and unless this bug is fixed, we can't really move forward with using Unity for our product.
     
  8. RalphH

    RalphH

    Administrator

    Joined:
    Dec 22, 2011
    Posts:
    592
    Hi, we found a workaround for this, which will be included in a future version of Unity.
     
  9. Dislay

    Dislay

    Joined:
    Feb 14, 2014
    Posts:
    1
    Can you let us know the workaround for this please?