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
0
Question by kkiniaes · Dec 09, 2014 at 08:50 PM · uispriteui imagegraphic

Can't change Image sprite because in rebuild loop?

I've combed the internet and found almost no one else with the same issue which is odd... All I'm trying to do is programmatically change the sprite property of an Image component of a UI element. This is the code I've got:

 quickAccessBar.transform.GetChild(0).GetComponent<Image>().sprite = common;

I have checked, there is a child of quickAccessBar, it has an Image component attached, and common is a sprite variable and references a texture that is imported as a Sprite. That all is there. Here are the errors i'm getting:

 ArgumentOutOfRangeException: Argument is out of range.
 Parameter name: index
 System.Collections.Generic.List`1[UnityEngine.UI.ICanvasElement].get_Item (Int32 index) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
 UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/CanvasUpdateRegistry.cs:107)
 UnityEngine.Canvas.SendWillRenderCanvases ()
 

And this second error happens for almost EVERY UI element in the scene:

 Trying to remove Image (UnityEngine.UI.Image) from rebuild list while we are already inside a rebuild loop. This is not supported.
 UnityEngine.UI.MaskableGraphic:OnDisable()

Any idea what's going on?

EDIT: I have tried and failed at replicating the error in another unity scene. Any idea what this rebuild list issue is?

Comment
Add comment · Show 2
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 hexagonius · Dec 09, 2014 at 09:25 PM 0
Share

I could not reproduce it. I Added a Canvas to the scene, added an Image so it was its child and added your code line to a script attached to the canvas. Could assign the image no problem. Using Unity 4.6 final

avatar image kkiniaes · Dec 09, 2014 at 10:21 PM 0
Share

I just played with it some more and did error pause to stop debugging when the problem occurs, and when i clicked on the game object with the Image component attached to it, the inspector view was blank. It looks like the game object is getting destroyed or something? I have combed my code and i don't reference that game object ANYWHERE else

2 Replies

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

Answer by kkiniaes · Dec 10, 2014 at 02:20 AM

Figured it out. For some reason I just needed to set the public sprite that i'm changing to (the one called "common") to "none", and then drag the sprite I want in to the public field again. For some reason Unity thought it was a Texture2D, not a sprite. Even though I had set the import settings to Sprite.

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 mitaywalle · Mar 17, 2020 at 06:25 PM

  • https://docs.unity3d.com/ru/current/ScriptReference/UI.CanvasUpdateRegistry.IsRebuildingGraphics.html

...

  • https://docs.unity3d.com/ru/current/ScriptReference/UI.CanvasUpdateRegistry.IsRebuildingLayout.html

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Color blending in UI sprite 1 Answer

Make images fit in UI 0 Answers

Unity UI not showing some Images 0 Answers

Change UI GUI Image Sprite at runtime .. Unity 5 .. js 1 Answer

Access sprite secondary texture in shader for UI canvas image 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