Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by MD_Reptile · Dec 16, 2015 at 05:52 PM · androideditorspriterendererresources

Sprites warped/not sliced on android builds, fine in editor

Note: possibly related to auto slicing sprites from script - see this question and answer here > http://answers.unity3d.com/questions/1113025/batch-operation-to-slice-sprites-in-editor.html#answer-1113065

I am working on little project on android, where sprites are assigned through code when prefabs are spawned at runtime. It grabs a load of textures from resources, then it takes certain sprites and assigns them at random to a prefab thats instantiated, and animates through a spritesheet for that particular sprite. The code works like this:

         private Sprite[] spriteArray;
         private List<Sprite[]> spriteArrayList;
         private List<Sprite> backgroundList;
         spriteArrayList = new List<Sprite[]>();
         backgroundList = new List<Sprite>();
 
         for (int i = 1; i <= 125; i++) // theres 125 sprite characters!
         {
             spriteArray = Resources.LoadAll<Sprite>("Sprites/Sprite (" + i + ")");
             spriteArrayList.Add(spriteArray);
         }
 
         for (int i = 1; i <= 178; i++) // theres 178 tiles!
         {
             backgroundList.Add(Resources.Load<Sprite>("Tiles/Tile (" + i + ")"));
         }

And then a random selected sprite is assigned when a prefab is spawned like this:

     void SpawnSprite()
     {
         int random = Random.Range(0, spriteArrayList.Count - 1);
         float randomX = Random.Range(camTopLeft.x, camBottomRight.x); // somewhere within limits spawn the sprite
 
 
         GameObject newSprite = Instantiate(SpritePrefab, 
             new Vector3(randomX, camTopLeft.y, -1), 
             Quaternion.identity) as GameObject;
         SpriteAnimate newAnimate = newSprite.GetComponent<SpriteAnimate>();
         SpriteMovement sM = newSprite.GetComponent<SpriteMovement>();
         sM.Speed = sM.Speed * level;
 
         newAnimate.SpriteSheet = new Sprite[spriteArrayList[random].Length];
 
         newAnimate.SpriteSheet = spriteArrayList[random];
     }

And in the editor this works no problem, however on device, specifically a Note 4, this causes graphics issues. Some sprites will show entire sheets instead of just a single sprite like intended, and some of the "splatter" sprites - which are left behind when you destroy a sprite - end up being stretched improperly. This looks like this:

alt text

alt text

I am kind of at a loss of where to start trying to fix things, but thought this must be a bug related to reassigning sprites at runtime, from resources. This is hard to diagnose considering it only happens on the device. I'll be testing in AVD here in a moment, but I'd bet the same result happens! Anybody know whats going on?

glitch1.jpg (207.2 kB)
glitch3.jpg (186.7 kB)
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 MD_Reptile · Dec 23, 2015 at 02:31 AM 0
Share

As another note, I created an editor script which takes those sprites, creates a prefab, and assigns them all to the correct sprites. This again works fine in the editor, and behaves the same on devices. Possible bug with auto slicing sprites from script? Updated question with a link to the script that does that process!

0 Replies

· Add your reply
  • Sort: 

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

41 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

hi guys, i'm new to unity, could someone help me, how can i import any image into unity that has a hd quality in the visual part of the player (game)? 0 Answers

Resources.Load too much on Android = crash. 0 Answers

Sprites and Mip Maps in Android vs iOS 2 Answers

What's wrong? Heavy game for Mobile ? 1 Answer

How to optimize the lighting in Android for best performance? 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