Unity of resource loading and AssetBundle some pit

https://www.cnblogs.com/sigmadruid/p/4040803.html

 

 

  • After AssetBundle loaded, wherein the initialization performed Asset can not immediately Unload (). Otherwise there will be problems Asset initialization, dependencies will Missing. Wait 2 seconds before an Unload (). Because Instantiate () also has a delay, although it can return a GameObject objects immediately.
  • Static Batch only work for static objects in the scene gracefully in advance. Loaded object might fail at runtime. Then you can call StaticBatchingUtility.Combine (GameObject root); manually trigger Static Batch.
  • uv light map information stored in the attribute uv2 Mesh is a Vector2 []. Import options model, if the check Generate Lightmap UV uv information will be automatically generated. However, when the model is packed into these AssetBundle uv lost. You can use the configuration file manually record. When loading these models, and through them the code will resume.
  • The model name (gameObject.name) and its Mesh's name (gameObject.renderer.mesh.name) is not the same.
  • AssetBundle pack out of the particles may be lost Shader. As long as the package of the project, the possible use of Shader added to Edit-> Project Settings-> Graphics-> Always Included Shaders this list on the line.
  •  AssetBundle where resources are as unloading AssetBundle disappear from memory.
    This is a disgusting problem. Consider a situation where you have three AssetBundle: A save Prefab, B preservation Mesh, C preservation Texture and Material. Dependency is A-> B-> C. So you turn loads C, B, A, then A in the Prefab to Instantiate a, get a complete GameObject. At this point, do not you think that the Sa AssetBundle unload it. Uninstalled, you find Mesh, Texture, Material gone. Because B, C where resources are dependent, but the lack of unloading not taken into account. But if you will be B, C things are Instantiate each one out, dependencies gone, can only add your own.
    Therefore, the relevant recommendations of the best resources labeled as a AssetBundle. Such dependency is stable. Or you maintain a dependency. This thing you pointed Unity, really not fly.
  • Do not loop iteration variable passed to the loop closure function. Because the loop iteration variable will be overwritten. You can create a local variable inside the loop to store the variables. Because the nature of the closure mechanism using an external recording or memory address parameter. This error in case you cycle to initialize some resources, and to get on pullbacks, it is easy to meet.
  •  After the editor mode, after changes to the Resources directory content, you need AssetDataBase.Refresh () to use Resources.Load () to read its contents.
  • AssetBundle reading resources, for example by Load (), LoadAll () and mainAsset, it can not be the Destroy. When AssetBundle is unloaded, they are destructed together. Best to Instantiate () out of a re-use. Texture2D, such resources Mesh, you need to check the Read / Write Enabled option in the import.

  • Some GameObject if the variable (array, List, Dictionary, etc.) are held MonoBehavior, must be at the OnDestroy (time) Manual destruction thereof. Otherwise it will cause a memory leak.
  • Does not create a dependence between Prefab, that is, if Prefab-A and Prefab-B cited with a texture, and they set up a different abName, while the share of grain is not set abName, then Prefab-A visual and Prefab-B is packaged separately, are included in each Bundle shared texture. Therefore, the use UGUI, open Sprite Packer, due to the Atlas can not mark abName, when setting UI interface Prefab the abName need to pay attention to this issue.

    Shader 5.x added to a stripping function, when packaging, default code Shader release of resources according to the case and Fog Lightmap set the current scene. This means that, if packaged in an empty scene, the Bundle of losing support for Shader Lightmap and Fog, which runs Lightmap situation and Fog lose situation. And by Edit-> Project Settings-> Graphics under shader Stripping change in the modes Manual, and check the appropriate mode to avoid this problem.


Guess you like

Origin www.cnblogs.com/alps/p/11209311.html