circle-loader
0
by
0/ 861/ /4

1) Questions about Addressable
2) How to perform the hot update of Addressable
3) How to set the Shader variable of SceneView camera
4) The reason why Activity defaults to SingleTask
5) About the Resources.UnloadUnusedAssets call time is too long

Today, we continue to select a number of issues related to development and optimization for you. It is recommended that you read it for 10 minutes, and you will be rewarded after reading it carefully.


Addressable

Q: I have been watching Addressable for the past few days. Although I don’t fully understand it, I feel that it is much easier to use than AssetBundle, and I have considered it very well. There were some questions when referring to Addressables 1.6.2:

  1. Compared with AssetBundle, how to control its packaging granularity? For example, AssetBundle can control multiple resources into one AssetBundle.
  2. Is there a script to automatically set the Addressable name and Label? After all, the slightly larger scale project has a large number of resources, and the manual setting was not scientific in the past.
  3. Regarding Check for Content Update Restrictions, there is a sentence in the official document: Note: This command will do nothing if all your changes are confined to non-static groups, which means that this check does not work for non-static groups. The question is, where is this Group defined? Is it non-static or static?
  4. Regarding Unique Bundle IDs, the official document is also Turn on “Unique Bundle IDs” within the AddressableAssetSettings Inspector, however, I didn’t find it.

A1: The first question: Addressable is finally packaged into AssetBundle, and the package storage directory is determined by the Build Path set by the BundledAssetGroupSchema of each Group. The Bundle Mode of the BundledsetGroup Schema determines whether the resources of the same Group can be packed into a Bundle. If it is Pack Together, it will be packed into a Bundle, and Pack Separately will pack each Entry into a Bundle. The issue of granularity is similar to the use of Asset Bundles. Addressable will automatically manage the dependencies of the Bundle packages. If the dependent resources are not in other Bundle packages, they will be automatically added to their own Bundles.

For the second question, you can refer to the details in the picture:

 

A2: Question 3:


Cannot Change Post Release == static
Can Change Post Release == non-static

Question 4

For more Addressable technical topics, please refer to the relevant courses of UWA School:
“Addressable System Analysis and Practical Experience”
“Addressable Advanced Practical Methods”


Addressable

Q: Please tell me how to perform the hot update for Addressable. In the previous project, all resources are packaged into AssetBundles and placed in StreamingAssets. The updated AssetBundles will be downloaded to the writable directory, and the AssetBundle of the writable directory will be loaded first when the game is loaded.

So how to implement this function in Addressable? Can you set a priority to read the directory?

A: I don’t know what does mean the title refers to by setting priority to read the directory. For the moment, let’s talk about it according to what I understand. The resource update function of Addressable needs to be handled in two aspects: Editor and Runtime. In the Editor section, you need to check to Build Remote Catalog in Setting. The Catalog files (.hash and .json files) will be generated after using New Build for the first time. These two Catalog files and the typed Bundle files need to be placed on the server superior. Then update the resources afterward, you need to Update a Previous Build to the package. At this time, the Editor will overwrite the original catalog files (.hash and .json files), and a new Bundle file will be generated at the same time, just replace the original file of the server with the newly generated file.

In the Runtime part, you need to call CheckForCatalogUpdates and UpdateCatalogs to update resources. When the resource is updated to the local, calling Addressable.LoadAssetAsync will automatically load it from the local directory. I don’t know if the local directory here is the priority directory mentioned by the subject.

The specific code can refer to:
https://answer.uwa4d.com/question/5e3b7fe686a39548919837e1


Camera

Q: To make an effect, you need to set a WorldToView matrix, and hang a script to set global variables on the main camera, but under SceneView, the WorldToView matrix of the main camera is still used. Is there any way to set the SceneView’s Camera properties when the SceneView is rendered?

A: If you want to synchronize the GameView camera to SceneView, you can try the following methods:

[InitializeOnLoad]
public static class SyncSceneViewMenuItem {
    private const string MenuName = "Tools/Sync GameView Camera to SceneView";
    private static bool enabled;

    static SyncSceneViewMenuItem() {
        SyncSceneViewMenuItem.enabled = EditorPrefs.GetBool(MenuName, false);
    this.Apply();
    }

    [MenuItem(MenuName)]
    public static void ToggleSync() {
        SyncSceneViewMenuItem.enabled = !SyncSceneViewMenuItem.enabled;
        EditorPrefs.SetBool(MenuName, SyncSceneViewMenuItem.enabled);
        this.Apply();
    }

    private void Apply() {
    Menu.SetChecked(MenuName, SyncSceneViewMenuItem.enabled);
        SyncSceneViewCamera.enabled= SyncSceneViewMenuItem.enabled;
    }
}
public class SyncSceneViewCamera : MonoBehaviour {
#if UNITY_EDITOR
    public static bool enabled;
    private Camera camera;
    private void Update() {
        if (SyncSceneViewCamera.enabled) {
            if (this.camera == null){
                this.camera = Camera.main;
            }
            UnityEditor.SceneView.lastActiveSceneView?.AlignViewToObject(this.camera.transform);
        }
    }
#endif
}

Android

Q: The Gradle project exported by Unity will configure UnityPlayerActivity as SingleTask by default. However, in actual testing, many third-party SDKs conflict with the configuration of SingleTask.

Is there any design reason why Unity uses this default configuration? What are some pitfalls if you modify to Standard?

A1: The main purpose is to prevent the game from being started and causing a second crash, but it is not enough to rely on LaunchMode as SingleTask. There will be third-party SDKs that require following their requirements. For example, Tencent channels require SingleTop: The LaunchMode of the game’s Activity is required to set to SingleTop. After setting to SingleTop, in the scenario where the platform pulls up the game, two game activities may be pulled up. Therefore, the onCreate of the game activity needs to detect whether the current activity is a duplicate game activity, if it is, then needs to end the current game Activity.
So the two-handed preparation is better. If you can use SingleTask just use it. If it doesn’t, use static variables to make judgments.

A2: This has a certain contribution to reducing the number of downtime statistics. Many times your game is not set to SingleTask, switch back to the backend and return to the game again. It may be pulled up again, which increases your downtime statistics. It has a big impact on the downtime rate.


Resource

Q: There are hundreds of skins, mounts, wings, and other appearances to display Prefab in the game. These Prefabs are loaded through AssetBundle. When the Prefab is created, AssetBundle.Unload(false) will be called to unload the AssetBundle, but GameObject and the corresponding resources will also be kept in memory.

The problem now is: After all these appearance models are clicked on the mobile phone when Resources.UnloadUnusedAssets is called for the first time, a lag that may be as long as 20 seconds will occur. If those GameObjects have been Destroyed, and the corresponding resources in the memory are all turned into the garbage to be recycled, it is understandable that calling Resources.UnloadUnusedAssets will be stuck for so long, but now the problem is that these resources are still being referenced and will not be cleaned up by the API? It has been confirmed that it is not caused by other resources and even the AssetBundle.Unload (false) interface has been tried to be blocked. The same operation will also cause a lag.

What are the possible reasons for this long lag? The Unity version is 2017.4.30f1.

Latest update: After testing a single Prefab resource (after calling AssetBundle.LoadAsset), calling c directly without calling any other released interfaces, the relevant display in the debug log is:
Unloading 27 unused Assets to reduce memory usage. Loaded Objects now: 6777.
Total: 20.391873 ms (FindLiveObjects: 1.497475 ms CreateObjectMapping: 0.186901 ms MarkObjects: 15.905487 ms DeleteObjects: 2.801631 ms)

The biggest question now is: how did this 27 come from? Which resources are marked as garbage and then deleted?

A: In the case of 20 seconds, is there a corresponding log? Look at which one takes a long time in the 4 steps, and what is the magnitude of Objects.

You can try to change your test code like this:

yield return Resources.UnloadUnusedAssets();
yield return Resources.UnloadUnusedAssets();  // Ensure that the output of this item is Unload 0
var info0 = CreateIDToInfoMap(Resources.FindObjectsOfTypeAll<Object>()); // Create a dictionary, Key is InstanceID,Value is object description

ab.LoadAsset();

yield return Resources.UnloadUnusedAssets();  
var info1 = CreateIDToInfoMap(Resources.FindObjectsOfTypeAll<Object>());

// Compare info0 and info1 and print out description, you can know which Objects are missing


That’s all for today’s sharing. Of course, life is boundless but knowing is boundless. In the long development cycle, these problems you see maybe just the tip of the iceberg. We have already prepared more technical topics on the UWA Q&A website, waiting for you to explore and share them together. You are welcome to join us, who love progress. Maybe your method can solve the urgent needs of others, and the “stone” of other mountains can also attack your “jade”.

YOU MAY ALSO LIKE!!!

UWA Website: https://en.uwa4d.com

UWA Blogs: https://blog.en.uwa4d.com

LinkedIn: https://www.linkedin.com/company/uwahub

Facebook: https://www.facebook.com/uwa4d

Twitter: https://twitter.com/uwa4d

Related Topics

Post a Reply

Your email address will not be published.