Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Can have preload version to reduce initial download ?

Discussion in 'Project Tiny' started by pcthomart, May 2, 2019.

  1. pcthomart

    pcthomart

    Joined:
    Apr 3, 2015
    Posts:
    6
    Hello

    I'm working on a instant facebook game, and in the facebook rules your games have to have an initial download size of no more than 3MB.

    upload_2019-5-2_10-19-17.png

    My build has a 6Mb size, I can of course try to reduce it but it will affect the graphics quality of the game.
    I don't need all the assets of the beginning, is it possible to make a preloading package, and loading the rest once in the game?

    Thanks
     
  2. Zionisias

    Zionisias

    Joined:
    Apr 23, 2019
    Posts:
    40
    It is possible, but might cost you some work.

    In the project I'm working on, we do XMLHttpRequests to our resource-server which sends us the images in base64 format. We receive these base64-images into the callback of the .onload of the request, after which we put the resources into the LocalStorage of the browser.

    Whenever we spawn in a new EntityGroup, a system we made will check for a certain resource-component on each entity, after which the system goes through a few steps to load the resource into the entity's Sprite2DRenderer for each entity with the resource-component:
    1. It will create a new entity with an Image2D-component and an Image2DLoadFromFile-component.
    2. It then sets the "imageFile"-variable of the Image2DLoadFromFile-component to the matching base64-file from the LocalStorage. (The key of the LocalStorage-entry corresponds with a string-variable in the resource-component.)
    3. The system will then create a new entity with a Sprite2D-component, and sets its ".image" variable with the previously created Image2D-entity. (I believe you could also instead of creating another new entity, use the previous entity with the Image2D-component and add the Sprite2D-component to this entity, then set the ".image" variable of the Sprite2D to its own entity.)
    4. The last step is to set the ".sprite" variable of the Sprite2DRenderer to the previously created Sprite2D-entity.
    5. The resource-component can be removed after the sprite has been updated, to prevent the system from picking up this entity again the next frame.
    Optional: You could check if a certain resource has already been loaded once, as the entity with the Sprite2D can be used in multiple entity's Sprite2DRenderer-components. This would mean that you only need to create 1 or 2 entities for each unique resource, instead of for each resource.

    The last thing to do in your case before releasing, would be to remove the images in the spriterenderers of the entities, and remove the images from your project.

    This works for us but also is still experimental for us, and there might be better or much better ways to accomplish this.
    Suggestions are always welcome. ;)
     
    reallyhexln likes this.
  3. pcthomart

    pcthomart

    Joined:
    Apr 3, 2015
    Posts:
    6
    Thanks!
    I see the concept, we are doing a similar mechanic to retrieve Facebook pictures of the players.
    Effectively it works and I can start with that.
    Like you, we are in experimental phase, and any other suggestions are welcome ;-)
     
    Zionisias likes this.
  4. gamayun

    gamayun

    Joined:
    Nov 20, 2012
    Posts:
    34
    Thanks Zionisias and pcthomart, I was thinking of doing that, it's good to know you already succeeded on that path.
    pcthomart, I'm wondering where you found this 3Mo size limit? I've read somewhere it is 200Mb for facebook instant apps but if you do InAd instant games then yes it has to be around 3Mo, am I wrong?
     
  5. pcthomart

    pcthomart

    Joined:
    Apr 3, 2015
    Posts:
    6