Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 testmaster217 · May 21, 2020 at 12:59 AM · uispritesui imageimages

Sprite.Create() only works the first time and eventually causes "Invalid AABB" errors.

So, I'm trying to have some images on a UI change based on data about levels in my game, and this is my code for one of those things:

contentPanel.transform.GetChild(0).gameObject.GetComponent() .sprite = Sprite.Create(lvl.ImageID, contentPanel.transform .GetChild(0).gameObject.GetComponent<Image>().sprite.textureRect, contentPanel.transform.GetChild(0).gameObject.GetComponent<Image>() .sprite.pivot);

"contentPanel.transform.GetChild(0).gameObject" refers to an image that is the first child of a panel on the canvas. lvl.ImageID is the thumbnail for a level.

The code runs whenever the player hits a button to open the canvas (it's actually always open, it's just hidden behind everything else when it's "closed"). The first time, it runs well, but the second time, the image I'm trying to load is drawn off-center even though the bounding box and pivot are in the right spot and the third time and afterward, the image doesn't draw at all (even though the bounding box and pivot are still right where they should be) and I get an error message that says, "Invalid AABB in AABB." The call stack never mentions my code. What is going on?

UPDATE: After more testing, I found that reloading the scene "resets" the bug.

ANOTHER UPDATE: I changed the pivot parameter in one of the Sprite.Create() functions to new Vector2(0.5f, 0.5f) and the problem got fixed for the thing that that function was helping to draw. (For anyone reading this in the future, I think that was only part of the fix, read the answers and comments.)

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sheepmccree · May 21, 2020 at 05:40 AM

Invalid AABB in AABB usually means that the texture you want to create a sprite of is not set to readable. I'm the inspector, in the texture import settings, make sure that "Read/Write enabled" is set to true. Also for the textureRect, you don't want to use the previous one, but the size of the texture. So, instead of contentPanel.transform .GetChild(0).gameObject.GetComponent<Image>().sprite.textureRec use new Rect(0, 0, lvl.ImageID.width, lvl.ImageID.height , if I understand correctly that lvl.ImageID is your texture What I suggested only works with single textures, not packed textures

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 testmaster217 · May 21, 2020 at 12:57 PM

@sheepmccree My texture is part of a multiple sprite image that isn't using an atlas. Does that matter?

Comment
Add comment · Show 2 · 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 sheepmccree · May 21, 2020 at 01:08 PM 0
Share

Read/Write should be enabled in that image as well. If you have multiple textures in one place, then looking at the Sprite.Create reference, it says "The second argument rect defines the sub-texture used. The rect argument is defined in pixels of the texture. A Rect(50.0f, 10.0f, 200.0f, 140.0f) would create a left to right range from 50.0f to 50.0f + 200.0f = 250.0f. The bottom to top range would be 10.0f to 10.0f + 140.0f = 150.0f." So, that means you have to somehow get that rect for each of your textures. I don't completely understand your use case, but I'll be happy to help if I misunderstood something.

avatar image testmaster217 · May 21, 2020 at 01:58 PM 0
Share

@sheepmccree I made the texture read/write enabled and changed the code to use a new Rect with the texture’s width and height and it didn’t change anything.

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

221 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 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 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 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 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 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

Picture loaded from resource corrupted. 0 Answers

How do I set a sprite to fill the entire screen in UI? 1 Answer

Animating a Sprite Image in UI from Code 1 Answer

Image renderer stretching sliced images 1 Answer

Circular 9 slice? Draw a circle with constant thickness 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