Hello Guest

Author Topic: Sprite Collection Mystery Junk  (Read 7368 times)

David Kalina

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
Sprite Collection Mystery Junk
« on: June 23, 2015, 10:58:46 pm »
Hello Unikron,

Having a mysterious problem.

Our build machine -- which grabs a pristine version of our game from SVN and builds target players from scratch -- is producing builds where a specific (very important) Sprite Collection is rendering with a bunch of mystery junk visible.  This is true in both in our iOS and Steam builds.  If I pull a fresh check-out from SVN and run the game in the editor, the problem is there too.

I don't know how better to describe this, so please have a look at the attached image.

As you can see:

- The image in the generated SC atlas PNG is pristine.
- It does not appear to be indexing out of bounds, it's just drawing garbage of no origin along with the correct artwork.

I can "fix" this by rebuilding the SpriteCollection.  It has NO effect on the SpriteCollection PNG data or the material.  It DOES, however, touch one line in the SpriteCollectionData prefab (also shown in the attached image).

Umm, so what the heck IS a buildKey anyway, and why would it change, and why would it have anything to do with this problem?

Now, the one bit of potentially useful information I have for you is that this particular SpriteCollection recently went through a change.  It was previously a PNG Atlas, and I changed it to a Unity Atlas (for the half-second of load-time increase that might grant us in our iOS build).  The TextureImporter associated with the Texture2D is setup properly.  There is no compression enabled or anything of the sort.

I have briefly noticed this in other, similar SCs -- rebuilding generally has "made the problem go away."  We're < 2 weeks from ship and I don't like mystery problems this close to the end.  Any ideas?  Any way to make this NOT happen again?

Thanks in advance for the support!
David


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Collection Mystery Junk
« Reply #1 on: June 24, 2015, 12:32:01 pm »
Hi,

Have you looked at the diff atlas texture settings? The meta files of the atlas texture might shed some light on this.

David Kalina

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Sprite Collection Mystery Junk
« Reply #2 on: June 24, 2015, 02:53:51 pm »
I "rebuild" the sprite collection and it starts working, with the only change in the .meta file being the buildkey (as I illustrated in the attached file above).  I submitted that change to SVN but the problem is still exhibited in the build.

OK, that's the .meta file for the SCData prefab.  The .meta file for the .PNG looks extremely straightforward, just like every other imported Unity texture.  I do not spot anything unusual.

I mean, do you look at this image and think "oh I've seen something like that before?"  It looks to me almost like the texture in memory was not initialized properly, like there are a bunch of random bits floating around and the actual Texture got uploded "over the top" of some random gunk.  But that makes about zero sense to me.

I flipped the collection back to "PNG Atlas" and it appears to be working fine, though this is not really a final solution as we intend to use more Unity texture atlases for load-time and load-memory benefits.

Any more specific suggestions you have would be helpful.  Thanks!



unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Collection Mystery Junk
« Reply #3 on: June 25, 2015, 09:08:40 pm »
Hi,

No, i've not seen this before.

To confirm, there are no changes to the atlas texture meta file when this happens?
What happens if you shut down unity, delete the libraries folder and restart? Does that magically fix itself or is it still broken?
After that, take that image + meta (atlas texture only), drop it into a new unity project, create a material and drop it on it.
Open it in Photoshop and look at the contents, does it look bust?

What we need to work out is if the image thats broken or the atlas building process.

David Kalina

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Sprite Collection Mystery Junk
« Reply #4 on: June 25, 2015, 11:39:04 pm »
Ugh, I had completely forgotten about Library. 

Our buildbot does a completely fresh rebuild -- that means there is no Library when it builds. 

So it is precisely at this point in time where the textures for the sprite collection(s) in question are messed up.

I perform a completely clean sync to a brand new folder, run Unity, let it build the library for an hour, come back...  and this problem is there.

I rebuild the sprite collection manually and suddenly the texture draws properly.  The only thing to change in my entire project at this moment in time -- outside of /Library -- is the SC's .meta file, which now has a different buildKey property.  I think I understand what that is well enough to know it's effectively meaningless.

And yes, having just diffed the current Library versus the pre-rebuild Library, a couple of files change.  Including a binary that clearly contains data for the sprite collection in question.

The IMAGE itself -- the actual PNG data -- is not different AT ALL before vs after. 

I'm thinking of writing a script into our build process that rebuilds all Unity Texture Atlas Sprite Collections in our project.  Which is insanely stupid to have to do... but it might work?



unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Collection Mystery Junk
« Reply #5 on: June 25, 2015, 11:54:30 pm »

youre missing the point entirely. Look at it objectively from what unity renders
a tk2d sprite is some geometry with an atlas texture.  first question is - are the artefacts in the texture or in the geometry. If it's in the texture, and it looks like it, AND the atlas texture png and meta hasn't changed,
Then something must be causing this. You just need to find why this is happening, may well be a unity bug or whatever, but the cause must be found in order to fix or work around it.

Point is, rebuilding the sprite collection is simply fixing the symptoms. You need to identify the cause or you're not going to get anywhere with this.

David Kalina

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Sprite Collection Mystery Junk
« Reply #6 on: June 26, 2015, 12:22:42 am »
I would love to identify the root cause, but given that I'm 26 months into a project and am trying to ship in a week, I really am not all that opposed to trying workarounds. 

As I've mentioned multiple times in this thread, the texture that is on disk is not the problem.  It does not change on disk AT ALL before vs after.

Is the texture in memory different from the texture on disk?  I don't know, I could try to look at that more closely. 

Is the texture in /Library different from the texture in the project?  I have no flippin' idea how Library works.  How would this even be possible?  Library is getting built from scratch but then is only updated after I click "Rebuild" on the SC?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Collection Mystery Junk
« Reply #7 on: June 26, 2015, 09:28:05 am »
Quote
Is the texture in memory different from the texture on disk?  I don't know, I could try to look at that more closely. 
Thats been my point all this time - if its just the texture that is the problem, then thats what we need to track down. Track that down and your reimport goes down from rebuilding the entire sprite collection -> fixing 1 texture which is MASSIVELY faster. Have you tried right click > Reimport on the texture? What about cmd+D to duplicate it - does the duplicated texture look broken?

All you need to do is create a material (pretty much any material), drag the atlas texture into the slot and drag that onto a plane in the scene, and try it with the different things above to see if any of them fix it. If any of those work, its easy to write a script that will do it automatically, vs having to rebuild every sprite collection, etc.

Obviously theres a balance between spending time fixing this and the workaround that you have, which is to rebuild the sprite collection, but imo its definitely worth spending the 1/2 hour figuring out why the texture is misbehaving - once you find that, hopefully we should be able to find a workaround closer to the problem.

David Kalina

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Sprite Collection Mystery Junk
« Reply #8 on: June 27, 2015, 10:00:11 pm »
Figured it out.

It was an "Alpha Is Transparency" thing cause by Unity forcing texture importer settings while in 2D mode. 

I keep trying to post this reply but the message board keeps complaining...  what if I keep it shorter?

David Kalina

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Sprite Collection Mystery Junk
« Reply #9 on: June 27, 2015, 10:01:08 pm »
(continued...)

Of course, the saved "Alpha is Transparency" flag in the .meta file is off, because that's how it's configured after being spit out by the SC builder.  Rebuilding the sprite collection doesn't change anything in the .meta file, I suspect that it actually just forces the Unity importer to update whatever is in the Library before it silently changes things behind the scenes. 

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Collection Mystery Junk
« Reply #10 on: June 28, 2015, 01:39:20 pm »
What version of 2D Toolkit do you have in your project?