U3D Addressables asynchronously loads resources to create a solution to large object lag

     In the current game, because it is a Xianxia game, the special effects are all hand-painted, and a lot of SPINE files are needed. There may be hundreds of animation files and textures on a protagonist, and it is very slow to create. It takes forty or fifty Seconds, try it out, set QualitySettings.SetQualityLevel, the speed increase is not big, about 20%, then it can only be solved by loading and creating itself.

First, clear the U3D cache before testing.

        Resources.UnloadUnusedAssets();
        System.GC.Collect();

U3D's garbage collection mechanism is like this. All variables and resources are marked first and then recycled.

The mark is the reference count. When the reference count is 0, it is marked as unallocated.

When will it be recycled?

1. When memory is allocated, there is not enough memory. If the memory is used up, GC will be triggered frequently.

2. Write code to force recycling.

3. The GC will be triggered automatically, how to trigger it automatically, but no information can be found.

This is why, the first time Resources.Load loads the image and creates the object, and then deletes it, creating it again will be very fast, because the deletion is just a resource such as the texture of the marked object, the reference count is 0, and it can be recycled, but it has not yet been created. When the GC is executed, all Resources.Load will be used directly, and the texture will not be read again.

 First, try Resources.LoadAsync.

        //Resource异步加载
        ResourceRequest prefab = Resources.L

Guess you like

Origin blog.csdn.net/u012322710/article/details/126053336