Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by JoelAtMoodkie · Sep 06, 2010 at 03:46 PM · editoriphoneinconsistentpacktextures

PackTextures works in editor but not on iPad/iPhone ...

Hiya all.

I've made a script which loads some objects, instantiates them and then uses PackTextures() to make a texture atlas so they all use one draw call. Simple enough I thought.

It works fine in the editor but when i load it to iPad/iPhone the textures are distorted. They look a bit like this image, but more pixelated:http://www.athlens.com/myspace-backgrounds/multicolor/color_multicolor_186.jpg.

Here's my code. It's a little messy as I've not had any time to tidy it up.

public static bool showMainGUI = true; public int iconWidth = 30; public int padding = 15; public Material newMat; //Created and assigned in inspector private GameObject[] tools; private Texture2D packedTexture = new Texture2D(1024,1024);

 private void Start()
 {
     useGUILayout = false;
     Object[] temp = Resources.LoadAll("Icons", typeof(GameObject));
     tools = new GameObject[temp.Length];
     Texture2D[] oldMats = new Texture2D[tools.Length];
     int xPos = 50;
     for(int i = 0; i<temp.Length; i++)
     {
         Vector3 instPoint = Camera.main.ScreenToWorldPoint(new Vector3(xPos,18,1));
         tools[i] = Instantiate(temp[i],instPoint,Quaternion.identity) as GameObject;
         tools[i].transform.parent = Camera.main.transform;
         // Cache old materials so they can be packed into atlas
         oldMats[i] = tools[i].renderer.material.mainTexture as Texture2D;
         xPos+=iconWidth+padding;
     }
     // Pack textures and assign atlas to our new material
     Rect[] texUVs = packedTexture.PackTextures(oldMats,0);
     newMat.mainTexture = packedTexture;

     // Assign new material to objects and adjust UVs accordingly
     for(int i = 0; i<tools.Length; i++)
     {
         tools[i].renderer.material = newMat;
         Vector2[] originUV = (tools[i].GetComponent(typeof(MeshFilter))as MeshFilter).mesh.uv;
         Vector2[] newUV = new Vector2[originUV.Length];
         for(int k = 0; k<originUV.Length; k++)
         {
             // Recalculate UV
             newUV[k] = new Vector2((originUV[k].x*texUVs[i].width)+texUVs[i].x,
                                     (originUV[k].y*texUVs[i].height)+texUVs[i].y);
         }
         // Reassign UVs
         (tools[i].GetComponent(typeof(MeshFilter))as MeshFilter).mesh.uv = newUV;
     }
 }

Any help would be greatly appreciated as I'm starting to get a little tired of the inconstencies between the Unity editor and the actual build.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JoelAtMoodkie · Sep 06, 2010 at 04:50 PM 0
Share

Also when I first load the project to iPad/iPod the textures will show up black. The next time I install it to iPad/iPod they'll come up with the distorted textures. Hope this helps!

2 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by JoelAtMoodkie · Sep 06, 2010 at 10:32 PM

Solved it. In Unity iPhone you must have "Get/Set pixels" enabled in import settings for any textures used in an atlas.

It might be useful to mention this in the Unity iPhone docs if anyone from Unity is reading this :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Maybe_memory · Sep 13, 2012 at 12:42 PM

hello.I can't find "Get/Set pixels" in import settings.can you put a screenshot here ?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DoktorAce · Oct 13, 2012 at 09:23 AM 1
Share

I think he means the option called "Read/Write Enabled" (4th from the top when you have a texture selected, and its "Texture Type" is set to "Advanced")

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Clearing Editor References when Building for Mobile 1 Answer

Have there been changes to PackTextures in 5.6 ? Seeing Artifacts in Scene which disappear in 5.5 0 Answers

Can I get some profile output inside unity iphone's editor itself? 1 Answer

Editor Crash: Where is Scene Data kept? 3 Answers

Dealing with GUI size on iPhone 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges