Hello Guest

Author Topic: Large projects and crowded atlases for IOS development  (Read 8466 times)

arkanoid87

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Large projects and crowded atlases for IOS development
« on: June 16, 2012, 01:20:37 pm »
Hi,

we're using TK2D for an iOS project where we need to pack over 15K images into atlases.

First problem: unity + TK2D cannot handle easily such a large asset (slowdown/crash/starvation even in PC/Mac destination, scared about trying in IOS mode), we had to discard "multiple atlases" option and separate manually over N atlases. So far, so good.

Second problem: we use uncompressed source images to build our atlases. The major problem is moving around sprite collections as it brings thousands of dependencies (slowdown/crash/starvation here too). We would really like to export just the data + material + texture atlas (*_data folder) unitypackage out from out "Atlas builder" project and use it into our destination project. Actually I'm trying to archive this by playing with TK2D source code but I prefer to look for a "bundled" solution first.

Thank you

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Large projects and crowded atlases for IOS development
« Reply #1 on: June 16, 2012, 01:33:19 pm »
You can do that easily - simply write a bit of code to save out an assetbundle and/or unitypackage, and then load that from your game/project as you see fit. As long as you're on a fairly recent version (1.7+ I believe) the inspector copes with not having the source images about - you just don't get the image thumbnails. You shouldn't have to modify the 2d toolkit code for this - well maybe to add a "post process" to save the unitypackage / asset bundle automatically.

The 2 project approach should work pretty well - it tends to be the norm with any large-ish unity project :( Sometimes I wish we had explicit memory management in Unity, it would be much easier to restrict memory usage like that.

There is a known issue with a large number of assets and "multiple atlases" - but the fundamental issue here is that Unity uses a ton of memory when accessing and manipulating textures (a lot more than it should). Turning off spanning is the best thing to do here, as you've already figured out.

arkanoid87

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Large projects and crowded atlases for IOS development
« Reply #2 on: June 16, 2012, 09:38:48 pm »
I'm using 1.70 patch2 but I'd say that your solution is not working for me.

After importing *_data folder (atla0, atlas0_material, data) from an external unitypackage, if I create a new sprite from menu (Create -> tk2d -> Sprite) and I click on it Unity logErrors "Unable to find sprite collection. This is a serious problem" and begin looping forever on "Rebuilding index" and I have no other solution apart from forcefully close Unity.

Do I have to look for a problem into the unitypackage or inside my unity+tk2d bundle (even if I confirm this bug into a clean empty new unity project)?

thank you

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Large projects and crowded atlases for IOS development
« Reply #3 on: June 16, 2012, 09:59:50 pm »
Give me a while to test this. I'm pretty sure this should be fixed now. I was pretty sure it was in 1.7, but I might have mistaken for a 1.75 beta. I'll test as soon as I get a minute and let you know.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Large projects and crowded atlases for IOS development
« Reply #4 on: June 17, 2012, 01:04:55 am »
I think you might have uncovered a bug here. This does indeed work, but in some cases, the index is recreated but never reloaded - it ends up using the old index, which is obviously a bad thing.

Could you try this please - in tk2dEditorUtility.CreateIndex(), add the following lines at the very end of the function
Code: [Select]
index = newIndex;
tk2dSpriteGuiUtility.ResetCache();

Once you import the new sprite collection package, invoke "2D Toolkit > Rebuild Index". When you create a new sprite, you should see the sprite collection you imported in there.

What worked for me -
1. In my original project, I simply select the _data project and export as a unitypackage
2. In my target project (blank project with only tk2d in there), I import the package
3. Run 2D Toolkit > Rebuild Index
4. Create sprite in viewport, and the sprite collection is available. The sprite preview is pink.

This worked in both 1.7 + patch2 and 1.75 beta 3. 1.75 beta 3 has a bit more code to handle a few more cases, for instance when the objects do not exist in the project, but only at runtime. This shouldn't affect you, though.

Let me know how it goes for you. In any case I'll be adding this fix to the codebase.

p.s. Even if the sprite collection data object is deleted after this, you shouldn't get an error in the view

arkanoid87

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Large projects and crowded atlases for IOS development
« Reply #5 on: June 17, 2012, 10:55:07 am »
Hi,

I've inserted       

Code: [Select]
index = newIndex;
tk2dSpriteGuiUtility.ResetCache();

at the end of static void CreateIndex() in static class tk2dEditorUtility, but I see no changes: Unity still loop around create index, debug message is displayed and I have to forcefully close the whole editor

This is how I reproduce the problem:
1) Start scratch new Unity project: target PC/Mac
2) Import 1.70 patch2 from asset store
2a) Apply your code modification (apparently does nothing for this bug)
3) Import my unitypackage that contains _data folder (3 objects)
4) From menu: 2D Toolkit -> Rebuild Index
5) From Hierarchy: Create -> tk2d -> Sprite
- ) A sprite with the "spider" body from demo assets appears
6) I click on the Sprite, I see the options in the inspector according to the "spider" body configuration, everything looks ok
7) I click on the "Collection" drop-down popup and I select my _data imported collection, Unity starts looping forever as I said

I cannot exclude that the bug is caused by a malformed _data export, but everything I can see from the inspector is a material slot and a texture slot over the "data" prefab

PS: as soon as I get access to the invoice number I will add my user to the registered users group

thank you
« Last Edit: June 17, 2012, 11:06:09 am by arkanoid87 »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Large projects and crowded atlases for IOS development
« Reply #6 on: June 17, 2012, 11:53:23 am »
Thats more or less what I've been doing without any issues. What would be really good is if you could send over the unitypackage to support@unikronsoftware.com - You can obviously blank out the texture png in photoshop, as I don't really need that. That way I'd be able to reproduce whatever you're doing and hopefully find the problem.

I've still got time before 1.75 is released, so hopefully I'll be able to integrate a fix in there if necessary.

arkanoid87

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Large projects and crowded atlases for IOS development
« Reply #7 on: June 17, 2012, 12:38:43 pm »
I've sent you the "data" prefab.

If you think that I should give a try to a "beta" version of 2D Toolkit please let me know.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Large projects and crowded atlases for IOS development
« Reply #8 on: June 17, 2012, 02:17:07 pm »
Got it, and taken a look - I have replied to your mail to further investigate how this has happened. Just for completeness, a quick summary -

The object GUID doesn't match the cached GUID, and all internal object connections to the material are now lost - implying something has been moved outside the unity interface. Anyway I'll post again once we've worked out what it is.

arkanoid87

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Large projects and crowded atlases for IOS development
« Reply #9 on: June 18, 2012, 12:41:24 am »
thank you. In the meantime I will try to re-commit & re-export on the atlas builder project.