- Home /
Download remote files to use at runtime
Hello great community :)
I'm working here on new project and one of the requirement is to keep client as small as possible... So we decide to stick to idea that client will download all required additional objects from server. The problem is that different clients will need different set of objects and it would be preferably to store each object/prefab individually on the server to avoid duplication. Then server can pack it up from the provided by client list of required objects and send it to client. Ideally I would love to download prepared prefabs (by it unique name) from server, but as far as I understand it is not simple as that to download prefab?
1) Am I right that if I download "some_file_name.prefab" and save it on client side to the resources folder I wouldn't be able to run it? 2) what if prefab was containing some AI scripts attached? would it not work?
I went through manual and come across AssetBundle thing, but it require pro version (what is fine with me) and as far as I understand it also have some complexity to run attached scripts (at least on iOS according to the manual what is very, very bad) Obviously I can include all AI scripts of all objects/prefabs on the client side as it is not heavy files and after attach required AI script to downloaded prefab but I would prefer to have it all in downloadbl object.
3) what if once server got download request from client with list of required objects - it would build zip file with all those prefabs and client just download zip? and then with c# libraries unzip it to Resources folder? would I be able to instantiate those prefabs?
I definitely know that I can download any file with use of C# and network programming in case if unity native API wouldn't allow me, but can I use these downloaded prefabs and instantiate them on the client? or to be able to instantiate objects I must use AssetBundle (preferably without scripts attached) full stop?
Answer by whydoidoit · Oct 03, 2013 at 11:35 AM
Well you cannot download code on IOS under any circumstance. It's a rejection reason and the runtime will just stop you doing it.
AssetBundles can have any scripts attached that are in your released app. It's normal to maintain asset bundle versions linked to versions of your app to make sure that there is no inconsistency (you pretty much have to do this).
AssetBundles are the way to go I would imagine - though perhaps it would be wise to make up packs of prefabs rather than just using a bundle for each prefab (though that is totally possible).
The only other thing you could do is download models and manually and recreate them, with your own code for what scripts to add and the variable values on them - this would be very painstaking and likely to lead to problems.
Thank you very much for a replay, ok I got it, AssetBundle is the only way as reconstructing objects from the script is huge pain and overkill
Regarding packing set of prefabs together on server would not suit as different clients could request different set of objects at different time. Today it might need one set, tomorrow another, so the best solution to have each object separate to do not duplicate tons of them on the server side. $$anonymous$$aximum what server can do is pack/group them up at request time and then delete, however I would need to do some skeleton implementation of this logic and test how big is delay time.
I'm still wondering what is the difference between AssetBundle and zipped archive with prefabs? The only thing i can come up with is that prefab is not an actual object, but just description of how objects are combined from other objects in resource folder and by exporting prefab to server the objects attached to prefab (like texture, sound, script) would not be exported with prefab
There going to be tons of objects, will need to automate Asset Bundle exportation functionality :)
thank you anyway! Have a great day!
Your answer
Follow this Question
Related Questions
download asset bundle when app is not active 0 Answers
Write Downloaded AssetBundle to Local Storage 4 Answers
Downloading Asset Bundle on Android and Saving to File 1 Answer
How to keep Adressable Asset Bundles downloaded in device? 1 Answer
Unity 5 Download AssetBundles from server via URL. 2 Answers