Author Topic: Sprite Atlas Broken on IOS (Fixed)  (Read 14728 times)

adramanto

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Sprite Atlas Broken on IOS (Fixed)
« on: January 29, 2014, 03:16:38 PM »
Unity Version: 4.3.1f1
NGUI Version: 3.0.8f6

Recently encountered a problem where the sprite atlas suddenly broke on IOS Builds but was still fine on Android. By broken, I mean that all sprites were either not showing up or displaying a really messed up texture. It turned out that in the texture import settings there was an IOS override that was capped out at 1024 and set to 16 bit. Turning off "Override for Iphone" on the sprite atlas seemed to solve the issue.

Just a general note that having texture overrides seems to break the atlas for IOS if the texture becomes larger than the capped size. Not sure if this is true for any other platforms but turning off the override in the texture import settings fixed the problem.


Khan-amil

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #1 on: May 14, 2014, 08:24:11 AM »
Kind of old thread, but the issue is still here, so helped me see what was wrong.
Is there any way NGUI could change this settting when creating the atlas texture?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #2 on: May 14, 2014, 11:06:04 PM »
If there is any way to choose the override settings via code, I'm not aware of it.

psngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #3 on: September 12, 2014, 12:17:29 AM »
I know that this is an old thread. But we are experiencing the same problem.

It happens not only when making iOS builds with override checkbox ticked, but also when reloading the scene after reducing Max Size in the Default tab of atlases. Note that it only happens when the size is made small enough.

It seems to us that NGUI doesn't pick up such changes made to atlases. Or to be more specific, the UVs of sprites are not updated when such changes are made.

Could you please have a look at the problem, ArenMook?

Not sure if this is related, but here are our settings in the UIRoot:
Scaling Style: FixedSize
Manual Height: 2048
Shrink Portrait UI: Unticked
Adjust by DPI: Unticked

Cheers,

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #4 on: September 12, 2014, 04:11:07 AM »
Unity can force change import settings of textures, and in some cases there is no way to determine that Unity did that, at least not through code. When an atlas is imported at lower dimensions than its native size, it breaks NGUI's functionality as sprite coordinates are specified in pixels, not UVs.

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #5 on: September 12, 2014, 06:26:13 AM »
I'm curious, why is the UV in pixels not float?  if they were float:[0,1] then it would work irrespective of the atlas size

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #6 on: September 13, 2014, 03:20:19 AM »
There are a lot of reasons. From readability in inspector to knowing native sprite dimensions, to having sprite's padding and border be specified in the same coordinate space as texture coordinates. NGUI 2 had a mess with both UVs and pixels, and it was a pain to work with and modify.

psngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #7 on: September 17, 2014, 08:08:29 PM »
Hi ArenMook,

Thanks for taking time to view and answer my question.

Is it possible to add a 'manually update atlas' button in Atlas Maker, so that when it's clicked it updates everything in the atlas with the current import settings? I reckon it will solve the problem that NGUI can't automatically pick up the import settings changes done in Unity.

The button will be handy even if it's not for import settings. The way we got around with the problem was to down-size all the images. But to update the atlases, we have to hand-pick all images which is time consuming and error pruning. An "Update All" or "Update Atlas" or "Recreate Atlas" button will be very handy in this case.

Cheers,

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #8 on: September 18, 2014, 03:21:10 PM »
You have full access to the data inside the UIAtlas (UIAtlas.spriteList). You can loop through it and change it as you see fit, including adjusting it based on some texture size.

psngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #9 on: September 22, 2014, 07:22:06 PM »
Hi ArenMook,

Thanks for the suggestion.

I wouldn't mind trying to fix the problem by myself. Your direction will be helpful. But the thing is that with my own modifications to NGUI there is long term impact on the project. If a new NGUI version is out with some feature we really need, we'll have to do the merge, which can be both time consuming and error pruning.

The request I made is not only an improvement of NGUI, but also a fix to known problems. Would you please consider implement it and include it in official NGUI builds?

Cheers,

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #10 on: September 23, 2014, 11:10:35 AM »
This wouldn't change NGUI. This would be your custom script modifying the sprite list of an atlas based on your code that's custom to what you're trying to do. You wouldn't be modifying a single NGUI script here, just making your own.

psngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #11 on: September 24, 2014, 07:06:19 PM »
Could you give me some details on how to do it so that no NGUI code is modified? I'd like a button somewhere in Unity so that when it's clicked, the chosen atlas get fully refreshed/updated/regenerated.

Also could you let me know how I can deal with the override settings of atlases? Is that something I can do without modifying NGUI code? Batch downsizing all the images in the game is just a temporary workaround. Ultimately we'll need full sized images to work. It means the override settings need to be working.

Cheers,

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #12 on: September 25, 2014, 06:59:10 PM »
What override settings? Not sure what you mean.

Create an editor script where you will choose an atlas you want to modify, then loop through the sprites of that atlas and change the data within. Don't forget to mark the atlas object as dirty. Not sure how else to explain this...

This is no different than working with any list in your own script. You have a list. Loop through it, change the data inside. What's so difficult about it? Why do you think you need to modify the List<> class to edit the items within it?

psngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #13 on: September 25, 2014, 07:56:26 PM »
Please check the attached image for what the override settings of atlases are. This is the main problem what this thread is talking about.

The main reason I asked about how to do it is because I'm not experienced in NGUI, and Unity. I wouldn't even understand what your solution (the editor window) means if I haven't luckily enough run into and learned about editor window two days ago. But anyway, thanks for the help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Atlas Broken on IOS (Fixed)
« Reply #14 on: September 25, 2014, 08:01:13 PM »
You shouldn't do anything with the texture import settings. They should remain at their largest possible size, otherwise NGUI's sprites will break as the dimensions are specified in pixels, not texture coordinates as I mentioned before. No, there is no automatic handling of downsized textures, because I am pretty sure there is no way to determine what the actual real size of a texture is. When Unity downscales it, it doesn't keep any info on what the original size was.