Author Topic: atlases caching redundant references to prefabs.  (Read 4231 times)

ferretnt

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
atlases caching redundant references to prefabs.
« on: January 18, 2015, 04:41:46 PM »
We are trying to optimize memory usage by ensure that specific screens (UIPanels) are only loaded, and thus there atlases are only loaded, when we require them.

I've tried this with various versions of NGUI, and there seems to be some way in which UISprites preserve incorrect references to atlases. It is extremely difficult to permanently remove all references to an atlas in the build player such that the atlas does not get loaded at all.

For example, we have one scene where we have three large atlases, each references by separate UIPanels. We have moved each panel to a separate Prefab, which is resource.Load()ed. We have also confirmed in the editor at runtime that right-clicking the unused atlases and selecting "Find References in Scene" returns no unexpected references, even after the prefab is instantiated. We have also confirmed that dragging the prefab into the scene and checking for references has no dangling references.

However, when building the player (for iPhone), all prefabs still incorrectly drag in all atlases.

I can give more details, and yes I do really know my stuff about Unity memory management, but would like to ask whether your aware of sprites caching redundant references to atlases before going into more detail.

There used to be a very similar case in NGUI 2.x (and it may still exist in 3.x) where the following sequence:

1. Switch an atlas to a reference.
2. Reference a half-sized version of the atlas.

Would still leave references to the full-sized atlas, although I'm not sure this is related, since in that case I suspect what happened was the Reference Atlas still held a dangling material reference.

I am quite happy to hand-edit prefab files to remove atlas references if that's required.

Alex

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: atlases caching redundant references to prefabs.
« Reply #1 on: January 19, 2015, 11:42:51 AM »
NGUI caches a lot of things to speed up the process.

To do what you are trying to do you need to use reference atlases. If you set up one atlas to be a reference atlas, you can make it point to the actual atlas that has the sprite information in it. All widgets would be using this reference atlas instead of the actual atlas with data in it, so when you want to clear the atlas reference you'd simply select the reference atlas and clear it there -- in one place.

This functionality hasn't changed since NGUI 2 days and is still the same in NGUI 3 and switching the reference will clear the cached values for you. Just make sure you're on the latest version of NGUI.