Author Topic: UITexture randomly gets changed into a UISprite  (Read 5233 times)

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
UITexture randomly gets changed into a UISprite
« on: July 10, 2014, 02:35:59 AM »
Hi there,
I'm using 3.6.6 and I've tried to create a UITexture with a button script and collider. The reason I use a UITexture is because the image for the button is downloaded from the internet, saved in memory and then loaded when needed. I noticed though that regularly, and it's not clear to me when, the UITexture component is replaced by a UISprite, thus making my game crash when I try to access the mainTexture parameter that UISprite doesn't have obviously.
Is it NGUI that changes that when I build my project for iOS or Android? Or is it Unity that does that? Again, I have no idea when this happens exactly, but after a bit I notice the error and I see that the UITexture has become a UISprite class.
Any idea why that could be? Is it because I attached a button component to it?

Thanks

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: UITexture randomly gets changed into a UISprite
« Reply #1 on: July 10, 2014, 03:05:01 AM »
UITexture is changed to UISprite when the UITexture component contains a texture that is included in an Atlas.

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
Re: UITexture randomly gets changed into a UISprite
« Reply #2 on: July 10, 2014, 07:02:00 AM »
holy shit, I didn't know this...that's not a cool behaviour. Thanks for the info!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture randomly gets changed into a UISprite
« Reply #3 on: July 10, 2014, 09:10:13 PM »
This only happens when you modify the atlas at edit time. The idea is that you can create your entire UI using UITextures, then select the UIRoot and create an atlas. It will automatically populate the list of textures for you with the root selected. After doing so, NGUI will go through the hierarchy and replace all textures with sprites.

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
Re: UITexture randomly gets changed into a UISprite
« Reply #4 on: July 14, 2014, 08:11:12 AM »
oh I see. My problem was that I needed to use the same picture as sprite and as UITexture so I had it the atlas but I didn't want my UITexture to change into UISprite because I had to override the image of my component with an image downloaded from the web. I still think there should be a warning message before NGUI overrides a component that way because this issue made my game crash for days and I had a REALLY hard time to figure out what the problem was because I didn't notice that my UITexture was changed at edit time of the atlas. Thanks

smallbit

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UITexture randomly gets changed into a UISprite
« Reply #5 on: August 20, 2014, 05:03:39 AM »
Really the worse idea ever have lost a lot of time in changing Uisprites back to UiTextures, very annoying, a popup would be appreciated !!.

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: UITexture randomly gets changed into a UISprite
« Reply #6 on: August 21, 2014, 02:51:36 AM »
If your texture is in an atlas, I don't get why you would want to use it as a UITexture.
Do this is just like duplicate your texture in the archive you want to generate at the end. You also risk to duplicate it in the memory of the device if your atlas and your texture are loaded.
So duplicate them is a non sense.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile

Mikeddd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UITexture randomly gets changed into a UISprite
« Reply #8 on: November 04, 2016, 03:29:07 PM »
Bumped this thread just to say this is absolutely infuriating. I lost half a day of work, because I just so happened to have made a backup today, otherwise I would have needed to update hundreds of sprites+hundreds of script references who lost the original UItexture reference. While the idea behind this makes sense, it doesn't apply to every case. A warning/popup of some kind is definitely needed. I updated the offending script to prevent this from happening, but it shouldn't have need needed.

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Re: UITexture randomly gets changed into a UISprite
« Reply #9 on: November 05, 2016, 04:51:53 AM »
Yeah, ideally it should not be the default behaviour, or at the very least it should never happen without a popup window requiring confirmation for replacement. I change this line after every single update to NGUI. :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture randomly gets changed into a UISprite
« Reply #10 on: November 05, 2016, 10:04:29 AM »
You'll find a toggle on the atlas maker for this in the next update.