Author Topic: Unable to change UISprite at runtime  (Read 3089 times)

n8

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Unable to change UISprite at runtime
« on: August 10, 2014, 11:31:12 PM »
I am attempting to change a UISprite to a new sprite from within the same atlas using this method:

sprite.spriteName = "newSpriteName";

When I run this, the sprite name changes in the inspector, but the actual sprite being rendered goes blank.  I am using the latest version of NGUI at the time of this writing (3.6.9). I have made sure that the sprite is set to use the "Simple" display type.

Thanks in advance for any help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unable to change UISprite at runtime
« Reply #1 on: August 12, 2014, 12:05:59 AM »
The button component uses the same code to swap sprites, and it seems to be working fine. Are you doing that at edit time? Is there more than one widget attached to the same object? Is there a panel on the same object? Need more info here... Try this simple test:

1. New scene.
2. ALT+SHIFT+S, choose one sprite.
3. ALT+SHIFT+C, attach a Button component.
4. In the "Sprites" Hover section, choose a different sprite.
5. Run, hover over the sprite.