Author Topic: Non-referenced textures are loading - anyone encountered this problem?  (Read 4834 times)

ChrisR

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
    • View Profile
Hey all,

So we have a scene where all sprites are assigned reference atlases. After testing these with HD atlases using a handy little debug script that shows the currently loaded textures, we saw that everything was fine - only the HD Textures are loading, as intended.

However, as soon as we change the reference atlases in the Project to point at the SD atlases instead, we run into a situation where both the HD and SD atlases are being loaded.

We ran a second debug script that tells us the UISprite which is using said atlases. Normally this works fine, but in this case it came up with no assigned sprites. 

One thing that came up earlier in the project was that if someone accidentally added two UISprite components to an object, even if the UISprites were pointing at a Reference, it would load SD instead. But we've solved those issues and stepped through each sprite and label in the game to make sure they are using references - both with scripts and manually to check.

I'll be doing some more specific testing today, but right now we're at a bit of a loss. Anyone got any experience with this and know what the cause could be? Any help is much appreciated!

gdeglin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 18
    • View Profile
Re: Non-referenced textures are loading - anyone encountered this problem?
« Reply #1 on: August 14, 2013, 08:21:19 PM »
I've experienced the same thing. I have a script that goes through all of our reference atlases and nulls out their target before I do a build then I load the appropriate atlas at runtime. All of the textures are put into asset bundles, so I see right away if a texture gets put into the project when it shouldn't be. (Using the Build Report tool available on the Asset Store).

It seems like removing the target from a reference atlas doesn't always kill all the references to the texture. Maybe a UISprite or UIPanel still holds on to something it shouldn't. Doesn't happen with all of my atlases, just some of them consistently. The fix has been to actually delete the HD texture, material, and UIAtlas prefab from the project then re-import them. It's a bit tedious, so I only do it before production builds. Maybe this is even something that can be automated.

I've experimented with using the new Profiler in Unity 4.2 to try to track this problem down but haven't found the cause just yet. I was hoping the latest version of NGUI would fix it but I believe it hasn't.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Non-referenced textures are loading - anyone encountered this problem?
« Reply #2 on: August 15, 2013, 07:07:30 AM »
UIPanel generates draw calls. Draw calls reference textures. Draw calls don't get updated until LateUpdate, so you need to unload your textures at the end of the frame -- yield new WaitForEndOfFrame() will do the trick.

gdeglin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 18
    • View Profile
Re: Non-referenced textures are loading - anyone encountered this problem?
« Reply #3 on: August 15, 2013, 03:00:14 PM »
Thanks ArenMook. In my case my unlinking code is in an editor class so I don't think I can use a coroutine like you suggest, or if this even applies to what I'm doing.

ChrisR

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: Non-referenced textures are loading - anyone encountered this problem?
« Reply #4 on: August 19, 2013, 05:15:21 AM »
Thanks for this. I'll have our coder look into it!

Though what I don't get is, if the game starts with the SD textures loaded into the project's reference atlases, why would it need to clear out / update the draw calls from HD to SD on sprites? Is that just a cache thing in the Unity Editor?
« Last Edit: August 19, 2013, 05:36:05 AM by ChrisR »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Non-referenced textures are loading - anyone encountered this problem?
« Reply #5 on: August 19, 2013, 08:56:25 AM »
Before building your game, set the reference atlas to point to nothing. This way nothing will be loaded on start.

ChrisR

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: Non-referenced textures are loading - anyone encountered this problem?
« Reply #6 on: August 23, 2013, 08:58:14 AM »
Awesome, thanks!

Washington Phillips

  • Guest
Re: Non-referenced textures are loading - anyone encountered this problem?
« Reply #7 on: August 28, 2013, 03:47:25 PM »
Before building your game, set the reference atlas to point to nothing. This way nothing will be loaded on start.

Even this doesn't work for me. I've "normal" atlases for 1x 2x & 4x for each UI atlas, stored along with their textures in Resources. The reference atlases are elsewhere in the project & cleared before builds, by having their replacement set to null. The proper textures are correctly loaded on Awake() at the start of the scene. Still, according to FindObjectsOfTypeAll and the profiler, all 1x 2x & 4x atlas textures are loaded as the scene begins. None of my other stuff has any reference to these textures.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Non-referenced textures are loading - anyone encountered this problem?
« Reply #8 on: August 28, 2013, 04:55:36 PM »
Are they in the Resources folder? If they are not, they are loaded automatically.

Washington Phillips

  • Guest
Re: Non-referenced textures are loading - anyone encountered this problem?
« Reply #9 on: August 28, 2013, 05:21:25 PM »
Yes. As stated, the only pertinent things outside Resources are the dummy/reference atlases. Must they also be in Resources for some reason?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Non-referenced textures are loading - anyone encountered this problem?
« Reply #10 on: August 29, 2013, 01:45:06 PM »
No, if their reference is deleted they should not need to be in the resources folder.To be honest, I'm not sure what's going on there.

sisso

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 46
    • View Profile
Re: Non-referenced textures are loading - anyone encountered this problem?
« Reply #11 on: August 29, 2013, 03:25:37 PM »
I think that this thread could be related with mine. Where even deleting the HD atlas, it is still referenced by some Widgets at Awake.

http://www.tasharen.com/forum/index.php?topic=5591.0