1) Mono memory problem for downloading AssetBundle 2) Unity 2019 runtime to obtain the prefab resource path in Hierarchy 3) display problem after merging multiple Submeshes models 4) Tolua access Time. DeltaTime is 0 5) Unexplained disconnect of CacheServer

This is the 242nd post of UWA technical knowledge sharing. Today, we continue to select a number of issues related to development and optimization for you. It is recommended that you read for 10 minutes.

UWA Q&A Community: Answer.uwa4d.com UWA QQ Group 2:793972859 (The group is full)


Q: The allocated memory cannot be freed when using coroutine +UnityWebRequest to download the Bundle.

Download the Bundle using coroutine +UnityWebRequest; 2. 2. Use BinaryWriter will UnityWebRequest. DownloadHandler. Data data to machine; 3. Call Dispose function of UnityWebRequest; 4. Call Resources. UnloadUnusedAssets (), UnityWebRequest. ClearCookieCache () and System. The GC. Collect ().

The above process will be performed for each Bundle downloaded, but the Profiler debugging machine found that the allocated memory could not be released, which would stretch the Mono memory. Have you ever encountered such a situation?

A: We have encountered A similar problem before, the subject can refer to, we use the version of Unity is 2018.4.31.

Both WWW before and WebRequest now use its member DownloadHandler for downloading. When you access the “.data “property, you’re actually accessing the wrapper of a” getData () “function that returns a copy of the Native Memory Data Buffer, which is where the root of the problem lies.

The first point you can optimize is to reduce the use of “.data “and cache it with temporary variables. The second one is to replace the downloadHandler, Unity provides a variety of downloadHandler, we were downloading images, so we used the downloadHandlerTexture, depending on your question, Can try DownloadHandlerAssetBundle.

Reference: https://docs.unity3d.com/ScriptReference/Networking.DownloadHandlerAssetBundle-ctor.html

Thanks to the Joke@UWA Q&A community for the answers


Q: art hope in running condition for scenario editor GameObject instance corresponding to the path of the precast body Unity before 2017 is by var pRoot = PrefabUtility GetPrefabParent (go); Return AssetDataBase. GetAssetPath (pRoot), the runtime precast path.

Recently upgraded to 2019, the discovery interface has been updated, PrefabUtility. GetPrefabInstanceHandle (targetGameObject), PrefabUtility. GetPrefabAssetPathOfNearestInstanceRoot (prefab) interface You can’t retrieve the GameObject path in the Hierarchy while Unity is running.

The key to my question is running state, which means clicking Play and getting the pre-made storage path on the Hierarchy. PrefabUtility. GetPrefabAssetPathOfNearestInstanceRoot (prefab) don’t play can be obtain, played only for precast storage path on the Project.

A: PrefabUtility. GetNearestPrefabInstanceRoot: access to the recent instances of precast body Root. PrefabUtility. GetPrefabAssetPathOfNearestInstanceRoot: prefabricated body path.

if (PrefabUtility.IsPartOfPrefabInstance(seletedGo))
    string prefabAssetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(seletedGo);

GetPrefabAssetPathOfNearestInstanceRoot access paths, “PrefabUtility. GetPrefabAssetPathOfNearestInstanceRoot (prefab)” not prefab part of the interface transfer, but the instance.

If this doesn’t work, hang a script or create a map in the Editor and fetch it at Runtime.

Thanks to the Jingfeng Ji@UWA Q&A community for providing the answer


Q: I tested a SkinMesh merge function and found that when the Mesh contains multiple Submeshes, it cannot be rendered after the merge.

When the test Mesh does not contain Submeshes, the display can be merged. Does CombineMeshes only merge Mesh without Submeshes? Don’t know what the problem is? Any ideas on how to solve it?

Note: whether to use “r.sharedMesh.Com bineMeshes (combineInstances ToArray (), false, false);” Take all the material, or “r.sharedMesh.Com bineMeshes (combineInstances. ToArray (), true, false);” Merges one texture material. Models with multiple Submeshes can only be merged without rendering. Models without multiple Submeshes can be displayed normally in combination.

A: Tests have found that you need to re-specify the triangulation for each CombineInstance in order to properly display models with multiple Submeshes.

Like this code:

foreach (SkinnedMeshRenderer smr in allSkineMeshList) { for (int sub = 0; sub < smr.sharedMesh.subMeshCount; sub++) { CombineInstance ci = new CombineInstance(); ci.mesh = smr.sharedMesh; ci.mesh.triangles = smr.sharedMesh.triangles; Ci. submeshIndex = sub; ci.transform = matrix * smr.transform.localToWorldMatrix; combineInstances.Add(ci); }}

Thanks to the Tauren for the @UWA Answers community for providing an answer


Q: Time accessing Unity in Tolua. Deltatime is always nil and the value assigned to the Lua variable is also 0. PS: The Unity API has been statically bound before Tolua can access it, and all other APIs can be accessed normally by Lua.

Why is Time. Deltatime 0 accessed in ToLuA?

A: Lua bindings must be written after the Lua virtual machine is started:

Thanks to the yxy@UWA Q&A community for providing the answer


Q: If the client opens the Cache Server panel and tests Connection, it will find that the Connection is not available. Then click the Server’s console and Enter.

Then the client can reconnect. How does it feel like it’s losing focus? What’s the reason?

A: Windows right-click Settings Properties/Default on the server’s console and “Uncheck Quick Edit Mode”.

Thanks to the aladdin@UWA Q&A community for the answers

Vasplinesnag is a spline tool for UE4 level designers. https://lab.uwa4d.com/lab/5b8627da02004fb65977efaf

That’s all for today’s sharing. Life, of course, is long and knowledge is long. The questions you may see are just the tip of the iceberg in the long development cycle, and we have already prepared more technical topics for you to explore and share on the UWA Q&A website. Welcome you who love progress to join us. Maybe your method can solve others’ urgent need. And the “stone” of another mountain can attack your “jade”.

Website: www.uwa4d.com Official Technology Blog: blog.uwa4d.com Official Q&A Community: Answer.uwa4d.com Official Technology QQ Group: 793972859 (The original group is full)