Assetbundle.load/unload vs. Resources.load


问:

Hi 

The AssetBundle is only provided by Pro version, so I think i need to Resources class to load and unload assets at runtime.

Resources class doesn't provide unload function to unload a particular asset as the same way as load.

It just have UnloadUnusedAsssets.

I want to unload an asset and release memory properly at runtime, but I'm having some trouble to do that with Resource.load/UnloadUnusedAssets.

I don't event know what's the best practice of UnloadUnusedAssets since there's no detail explanation of the function.

May I have more detail and advice on that here?

For runtime load/unload assets, do i really need AssetBundle with Pro version?

Is there any good way to use Resources.load/unloadunusedassets to do the same thing?

回答:
There are ways to missuse both methods.

The main difference between the two is actually the fact that assets that reside in one of your Resources folders are added to the build itself. This is nasty if you are deploying a web build.
We use this for example to load texture sequences. If you have 400 textures assigned to some script in your scene - they need to be serialized, which takes up a LOT of space in the scene and in the operational memory when the scene is loaded. If you load them one by one using Resources.Load they take up space in the build, but NOT in the operational memory. We deployed to a stand-alone build, so that wasn't an issue for us.

Asset bundles are NOT in your build, and can be streamed on demand using the WWW class. This is great if you want to stream assets more effectively or if you want to create new content AFTER you already deployed your build.
When you use them, they need to be serialized by unity for access, which takes up memory, and I assume the Unload function takes care of that issue.

In both methods the assets that you already loaded into your scene DO NOT get cleaned automatically when you use Unload (unless you use AssetBundle.Unload(true), which will delete the objects from the scene, and will allow unity to clean it later on). What cleans up your memory is the Garbage Collector, so I advise you to read up about it in the forum. 
You need to Destroy() assets and remove all references to them in order to clean the memory after loading them. The unload functions unload UNUSED assets or the data that had to be created for the assetbundle (No idea exactly what gets cleaned up and how much you will gain, but it's a good practice to do it IF you use dynamic loading of assets).

But before all this - think about if you actually NEED dynamic loading of assets... There are pros and cons that you need to concider before making that decision, and if you don't need them - you won't need the Unload functions.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值