Search Unity

GIGANTIC PROBLEM SOLVED!!!! Finally

Discussion in 'iOS and tvOS' started by frozenpepper, Jan 15, 2009.

  1. frozenpepper

    frozenpepper

    Joined:
    Sep 17, 2007
    Posts:
    222
    Hi all! I write this post to share my experience so that maybe could help somebody!

    It was since the middle of december that I was figthing with unity iphone, beacouse my game would crash after a few minutes of gameplay, and today I finally did a very basic thing that changed everything!
    GUITexture have to be power of 2 or the unity will use immense amounts of memory to handle them. I have about 15 GUITextures in my game all not bigger than 50 *50 pixels, and as soon as I changed all of them to power of 2 sizes my game begun to work perfectly!
    Unity inspector doesn't show this.....
    I'm now very happy, but if i had knew this earlier my game would have been finished by now, instead I thought the problem was with my code wich is quite complicated (instruments did not work due to the amount of memory requested by the game) and re-wrote everything many times, making hundreds of tests on the scripts.

    Hope this can help!
    Bye all !
     
  2. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    I had a similar experience a while back that involved running some code in the OnGUI function. I spent a month optimizing my game to run as smoothly as possible, and at the end of it all moving one line of code got me an extra 10 fps. I initially had the same reaction as you, wishing I had known that a month ago. However, looking back I'm glad that I didn't because now I can rest assured that my entire game is optimized to it's full capacity, not just that one script. That, and valuable knowledge was gained in many areas of optimization.
     
  3. frozenpepper

    frozenpepper

    Joined:
    Sep 17, 2007
    Posts:
    222
    You are more than right, and especially I have learned a lot about unity in this period, but I even changed all the 3d models and textures in my game hoping in a performance gain,(and i now think it was not needed), and the Ai of my game as been reduced a lot (actually now it's more of Artificial Stupidity than Intelligence),
    and I really don't want to go back rewriting everything..... Since it's quite of a basic problem it should be mentioned a little bit more in the documentation, while instead from what I had read it seemed that if used on GUI stuff textures could be the size i wanted......
    Anyhow now I'm happy and my game works!!!!!
     
  4. cheezorg

    cheezorg

    Joined:
    Jun 5, 2008
    Posts:
    394
    Have you noticed a difference when these textures are set to RGB 16bit or is this only with compressed textures??

    I have several GUI textures I'd like to keep at RGB 16bit, and from what I understood, the only difference with non-power-of-2 textures is that Unity is unable to compress them to PRVTC, which I don't want anyways.

    However, if there is a performance difference with RGB 16bit as well, it may be worth it to rethink my GUI.

    Also, the warning in Unity is a little confusing:
    "Texture size is not a power of two. If you don't use it on a GuiTexture compression will be turned off."

    I had thought this to mean that as long as I use an image on a GUITexture, Unity could still compress it, but otherwise, no...
     
  5. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    This is a limitation of the iPhone hardware--it can only compress textures that are power of 2...
     
  6. frozenpepper

    frozenpepper

    Joined:
    Sep 17, 2007
    Posts:
    222
    the warning you are mentioned is exactly what fooled me for all this time.... I thought that there was non problem with the images I used for GUITextures, instead....

    Regarding the 16 bit question, I really cant help you, do from what i understood you have to use prvtc wich has no 16 bit option. I didnt feel any difference using 2 or 4 bit compression Rgb or Rgba!

    If it is an iphone limitation, it should be mentioned somewhere in Unity! Unity is made for people who want an easy experiece from the technical point of view, especially if they advertise the fact that I could easeally port a project from regular unity; and my texture problem has not been easy to discover...
     
  7. jeffcraighead

    jeffcraighead

    Joined:
    Nov 15, 2006
    Posts:
    740
    You can always use the Power of 2 scaling options in the import dialog as well (although it won't look as good as an original that is power of 2). I didn't know this would give a big FPS boost though, so now I'm going to go back and check all my images.

    Thanks for the heads up.
     
  8. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    The OP mentioned crashing resolved with power of 2, not speed increases. Tat was a different poster, and he was talking about OnGUI not power of 2.
     
  9. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    But my question is, if we use power of 2 rather than 380x240 for fullscreen UI then quality will lose, right?

    There is way like mapping UV. We can put all UI texture in a single 1024x1024 then map the UV accordingly. But the SAD news is there is no way to do this for GUITexture in Unity. What you wanna do in that case? Any advice?

    Thanks
     
  10. frozenpepper

    frozenpepper

    Joined:
    Sep 17, 2007
    Posts:
    222
    From what i've experienced since yesterday that I discovered this, i noticed that if you simply "scale to larger" you 480*320 UI image and set the size of the GUITexture with pixel insect to what you need the result aren't bad at all and I didn't noticed a big quality loss.

    Eventually you could use a 512 *512 png image with transparency where you need it...
     
  11. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    Thanks taio84. I will follow you?

    Is there any other way? Guys?
     
  12. IPete

    IPete

    Joined:
    May 15, 2008
    Posts:
    414
    I did something like this recently for iPhone, I moved my animated title screen from onGUI to texturing a quad (which I built in Max 5.1 and exported as an fbx).

    The quad (2 x triangles) is used to hold my animating titles as 512 x 512 textures in the centre of the screen. I used a second camera and switch it on and off whilst the game plays, using the in game MainCamera to follow the game. My Titles look fab, no blurryness as far as I can tell.

    In Photoshop I had my Title gui made in 480 x 320. Then I resized the CANVAS to 512 x 512 and imported those 512 x 512 textures into Unity iPhone. Texture wise I use the transparent/diffuse setting.
     
  13. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    Awesome!!!

    But it will only effective on UI not in game UI [HUD]. Because we have to put Button like think as overlay, right? So,

    1. we can use it like a sequence of QUAD for all different menu to represent the back image which is huge save not load different scene. by this we are not losing quality.
    2. this will be not effective for in in game.

    Please correct me if I missed anything.
     
  14. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    You shouldn't have any noticable quality loss if you up-sample your images to a higher power of 2, as long as you're displaying it at the intended aspect ratio.

    By the way, since we're talking about using quads to draw UI elements, I thought you guys might find this useful:
    SpriteManager

    It will generate quads for you that are drawn like 2D sprites. You should be able to use it in many cases for UI elements and background images. The nice side-benefit is that you can use it to draw multiple objects that move or display independently but combine to use only a single draw call, saving you tons performance.
     
  15. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    Thanks Brady. :)

    The SpriteManager is one of the cool staff of this forum. I'm hacking your SpriteManager ;)

    Thanks again.
     
  16. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I don't want to hijack the thread, but, grinder, if you make any interesting changes/additions to SpriteManager, be sure to post them over at the SpriteManager thread. I'd be really interested to see what others do with it and so I can incorporate changes into it if they look promising. Thanks for the kind words!
     
  17. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    I will do, Brady :) and we should do.
     
  18. Aubrey-Falconer

    Aubrey-Falconer

    Joined:
    Feb 13, 2008
    Posts:
    438
    Many, many thanks Taio!

    I was in the exact same boat that you were - that warning message had me totally fooled.

    Look forward to much greater reliability in Mars Explorer iPhone 1.2 :)