- Home /
What would be the best approach to making a puzzle game that downloads levels dynamically
Hii everyone, So I am working on a tile-based puzzle game for android/ios and the requirement is that there will be 300 -400 levels which obviously is way too big for mobile devices. So we have to download the levels dynamically from google drive and do a download, caching and delete mechanism to keep app size in place. I was able to make the asset bundle, upload it to google drive and then download it in-game and using it. But I can't figure out the best way to make this system work inflow.
The basic flow is that each level has 1 colorless image, 1 colored image, and 1 main image for the puzzle. the colorless image and main image will be shown in the menu. (the colorless image will be changed to the colored image when the level is unlocked). It is to display what the level looks like. Once you click on the image then the main game will start in a new scene with the main image.
The level selection grid in the menu will have all the levels from before (locked or unlocked), as the player keeps browsing, the colorless images need to keep downloading and get shown in the grid.
//Code I use to download from the drive
void LoadFromWeb()
{
string assetBundleURL = "https://drive.google.com/uc?export=download&id=1rNvFLMrhG3C2Dj0pabMFGmnZIxC5w7-E";
StartCoroutine(AssetBundleHelper.LoadAsset<Sprite>("player6", assetBundleURL, 2, (bool isSuccess, Sprite spriteObject) =>
{
if (isSuccess == false)
{
throw new UnityException("Failed to load test sprite");
return;
}
this.testImage.sprite = spriteObject;
Debug.Log("Loaded from web");
}));
}
Shall I upload each level as an individual asset bundle, so I can download the level on demand? But then I will have like 300 links to handle (individual link for each level)
Or, should I upload like 10-20 levels in one asset bundle, so there will be fewer links. But, then I will have to download the entire asset bundle of 20 levels to download 1 level.
Ideally, I want to that all the levels are in the drive-in one folder and I can download levels on demand by maybe using the name or number system. I don't know how to go ahead with this. Any suggestion and feedback would be good.
Answer by Bunny83 · May 29, 2021 at 11:11 PM
While dynamically loading levels from your server is an option, 300 - 400 levels is not really much depending on the complexity. Of course it highly depends on how those levels are actually stored / generated and what they are composed of. If each level is a seperate Untiy scene, yes, that would probably be too much data. Though since you said the levels are tile based, such data can be stored quite compact.
If you want to go the assetbundle route and Untiy levels, you can of course do that. To answer your question: I would recommend to group some levels into one package. Maybe something like 10 levels (depending on the size of a level). You usually want to cache / keep as many levels as possible on the user's device. Otherwise the user need a permanent internet connection while playing.
About the actual management of your levels, I would recommend you provide a json file that contains the actual links to each assetbundle. So you can even update the list of levels without the need of updating the app itself. Likewise you want to remember locally which assetbundles you already downloaded. Generally its recommended to store this information for each assetbundle:
download link / URL
size in bytes
some kind of hash to verify the integrity of the file
Additionally you may store for each bundle the timestamp when the user played a level from that bundle the last time. This may be useful to decide which bundles you may delete if you run out of disk space.
Keep in mind that there are quite different kinds of users. Some may play mainly offline so they want to keep all levels available once installed. Other players may just play through the levels once and are ok with you deleting the completed ones. Of course if your game does not allow the replay of a level this is out of the question. However most games allow to replay levels. So you might want to make this behaviour configurable by the user. I remember playing some simpsons game on my old nexus tablet which required at least 500MB of memory because it contained something like 250 upgrades with a lot of additional assets. So it's not that unusual to have games that require a lot of disk space. Though of course you want to keep it as low as possible.
Instead of rolling your own system, you could use Unity's addressables package. I haven't use it myself, but it has many options how you can actually create content libraries and specify where and how to fetch them. You may read through the different topics in the documentation.
In the end I just like to mention that you ask too many different things in your question and essentially asking for a complete solution. Please note that UnityAnswers is for concrete questions that can be answered. Questions that ask for suggestions, opinions or feedback do not belong here. Please ask such things on the forum. The forum is for discussions. Such open questions tend to never have a clear answer and will never be "answered" and would be bumped regularly. Again, this is not the scope of UnityAnswers.