Hello Guest

Author Topic: Asset Bundles / Sprites with platform issue  (Read 10148 times)

MattGogii

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Asset Bundles / Sprites with platform issue
« on: April 23, 2013, 07:08:17 pm »
Hi, I'm having an issue building an asset bundle of a tk2dSprite.  The sprite has 1x and 2x platform information but when I select the game object with the sprite attached to add it to the asset bundle (tracking dependencies) it doesn't include the atlas or material for either platform, just the sprite collection data.  If I add an animated sprite game object the bundle is built with the atlas and material for both platforms seem to be included. Using Unity 4.1.2 and 2dToolkit 1.90.  Should I be updating the the latest plugin or is there something else I can do?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #1 on: April 23, 2013, 07:44:08 pm »
Asset bundles are not directly compatible with platform sprites. The reasoning behind it is if dependencies were respected, you'll end up with both sprite collections in there, which kinda defeats the purpose of asset bundles anyway. It is more appropriate to create multiple asset bundles, one for each platform, and load the appropriate one as an when needed. Its not ideal with animated sprites, but you could factor this in as part of the build process - it should be pretty straightforward to get a build script to switch the sprites in an animated sprite before building it into an asset bundle.

There isn't really an ideal automated workflow for this, as a lot of this depends on how you're architecting your game.


MattGogii

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #2 on: April 23, 2013, 08:02:04 pm »
So rather than using the platform system, create 2 of every sprite? Or is there an easy way of telling the sprites to depend on one platform or the other and then building the bundle after that. I'm find with building an asset bundle for each platform is there's a way to split them using the platform info that's already there.  I'd rather not duplicate all the sprites and rebuild a 2nd set of everything if possible.

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #3 on: April 23, 2013, 08:34:05 pm »
The interface stops you from explicitly selecting the platform sprite collections themselves, but you can change the UI so it'll allow you to do it:
in tk2dSpriteGuiUtility.cs, in the function BuildLookupIndex()
comment out this line:
Code: [Select]
//if (!i.managedSpriteCollection)

Now you will be able to select the @1x & @2x sprite collections explicitly. Basically you'll be able to use the system to do all the work - when you refer explicitly to these sprite collections rather than the base one (the one without @), the dependencies will be imported automatically. I suggest doing this in a separate project, so you won't have to then remove these from the build explicitly.

MattGogii

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #4 on: April 23, 2013, 08:41:05 pm »
Awesome, I'll give it a shot.  Thanks.

MattGogii

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #5 on: April 24, 2013, 07:55:26 pm »
That does seem to work which is great.  I've got a new issue though in that the textures that I'm adding to the asset bundle aren't being removed from the build even though the game objects are no long in the resources file.  I'm guessing this is due to the resources/tk2d folder that seems to have pointers to all platformed collections.  I would remove that whole folder but only some of the tk2d sprites are going to be in bundles while others will remain in the resources folder.  Is there anyway to split those or not have all the collections be pulled into the resources directory?

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #6 on: April 24, 2013, 11:19:17 pm »
Yeah that is expected. That is why I suggested building the asset bundles on a separate project.
If that isn't possible, I can suggest a little hack to make these ones not generate in the resources folder.

MattGogii

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #7 on: April 26, 2013, 06:57:37 pm »
So I branched the assets out of the main project into their own project and use the branch to create the asset bundles.  I made some editor scripts to force the sprites to use either the @2x or @1x collection and that works fine for regular sprites but I can't seem to get the setting to stick for animated sprites, or I'm missing something because when I use the asset bundles in the main game it errors out on

 platformSpecificData.Init();

in tk2dSpriteCollectionData inst

In the inspector the sprites are all set to a default animation and not the one included in the bundle.

Any ideas?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #8 on: April 26, 2013, 07:32:14 pm »
If you were doing this platform stuff, I was under the impression you'll be setting up the animations in the other project too? Wouldn't that make sense? Then you could have an editor script to create the 1x & 2x ones in the other project, and just import the appropriate one in on your other project.

MattGogii

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #9 on: April 26, 2013, 07:46:12 pm »
Everything was set up in the main project.  I've got characters with animations, buildings and cutscenes that I want to turn into asset bundles (hd and sd).  I've moved those assets into another project (everything, the collections, frames, prefabs) and I'd like to use that side project to build the asset bundles. The main game no longer needs to have any references to the assets in the editor since it can just load from the asset bundles.  This is working for regular sprites but I can't get the animated sprite bundles to include all the required assets it seems.  My editor script to toggle the sprite animation by looping through all the clips and changing the collection.  I may need to set the collection somewhere else as well, I'm not sure.

animatedspriteobject.anim.clips.frames[j].spriteCollection = data;  is how I'm changing the frames to point to the @1x or @2x collection.

for changing regular sprites with an editor script I'm using

spriteobject.SwitchCollectionAndSprite(data, 0);

Another thing is that tk2d is constantly rebuilding the index now that I've linked some of the platform collections to my sprite prefabs.  So the sprite points directly at the @2x or @1x collection instead of the reference.  Is there a way to prevent the constant rebuilding, right now it scans the folder, then seems to finish, then does it again, forever.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #10 on: April 27, 2013, 09:36:31 pm »
Your editor code looks perfectly fine.

About the rebuilding index, which project is this happening on?
The main one or the imported one? Does it work on one and not in the other?

MattGogii

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #11 on: April 29, 2013, 08:37:08 pm »
I did manage to get it working.  I wasn't calling setdirty on the modified assets to unity wasn't saving the changes.  I did have to delete the main collection with the platform info and just keep the @1x and @2x collections.  If I didn't remove the main collection it was getting included into the asset bundle for animations for some reason and was causing script errors when checking for platform data in the bundles.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Asset Bundles / Sprites with platform issue
« Reply #12 on: April 29, 2013, 10:14:59 pm »
I'm glad you got it working.