Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Engine Code stripping and Asset Bundles

Discussion in 'Scripting' started by Dynamoid-Megan, Mar 29, 2016.

  1. Dynamoid-Megan

    Dynamoid-Megan

    Joined:
    Apr 16, 2015
    Posts:
    72
    Hello Everyone,

    I was wondering if anyone could tell me why using Asset Bundles requires building for WebGL without Engine Code stripping? (I am currently using 5.3 still)

    My concern is that if I don't strip the engine code my WebGL output will be a huge file, and memory is always an issue enough as it is with WebGL.

    The error I get when loading a bundle if I do not uncheck the engine code stripping option is as such:

    Could not produce class with ID 33.
    This could be caused by a class being stripped from the build even though it is needed. Try disabling 'Strip Engine Code' in Player Settings.

    Could not produce class with ID 65.
    This could be caused by a class being stripped from the build even though it is needed. Try disabling 'Strip Engine Code' in Player Settings.
     
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,077
    As far as I know the basic problem is that the 'engine stripping' removes all unused engine functionality in the scenes that you build the application with. However, if you happen to use a component (say RigidBody) in one of the asset bundles but not in the main build scenes then that component would be missing when the asset bundle is loaded and you will get the above errors.

    One way around it is to include all the components that you use in the asset bundles in an empty scene and then include that scene in the main build - that will force those components to be included in the build. That way you can still enable engine stripping.

    p.s. You can find the IDs of missing classes here (http://docs.unity3d.com/Manual/ClassIDReference.html) - looks like you need to include MeshFilter and BoxCollider in your scene
     
  3. Dynamoid-Megan

    Dynamoid-Megan

    Joined:
    Apr 16, 2015
    Posts:
    72
    Thank you for the explanation!
     
  4. ratmat2002

    ratmat2002

    Joined:
    Jun 13, 2014
    Posts:
    35
    A better way is to place a link.xml file in the Assets folder of your project. This file is used to give the linker specific instructions including when to preserve (that is NOT strip) certain classes. You find the classes by ID here (http://docs.unity3d.com/Manual/ClassIDReference.html) and then add the fully qualified class name to your link.xml.

    Our link.xml looks like this:

    <linker>
    <assembly fullname="UnityEngine">
    <type fullname="UnityEngine.Avatar" preserve="all"/>
    <type fullname="UnityEngine.EllipsoidParticleEmitter" preserve="all"/>
    <type fullname="UnityEngine.FlareLayer" preserve="all"/>
    <type fullname="UnityEngine.ParticleAnimator" preserve="all"/>
    <type fullname="UnityEngine.ParticleRenderer" preserve="all"/>
    </assembly>
    </linker>
     
    Nolex, Saicopate and McDev02 like this.