Forum rules - please read before posting.

Performance issue - Unity UI + Inventory

I just stumbled over a performance issue that (at least in the editor) results in hitches of ~300ms when shifting the items of my inventory bar.

From what I've discovered, the issue lies in UISlot.SetImage() where a sprite is create dynamically when the texture changes. The default sprite constructor will create a "tight" sprite mesh. This takes some time as apparently the whole texture is scanned to figure out the actual non-transparent pixels for the tight mesh. I've changed the line

sprite = Sprite.Create (_texture, new Rect (0f, 0f, _texture.width, _texture.height), new Vector2 (0.5f, 0.5f));

into

sprite = Sprite.Create (_texture, new Rect (0f, 0f, _texture.width, _texture.height), new Vector2 (0.5f, 0.5f), 100F, 0, SpriteMeshType.FullRect);

and it solved the issue (still, sprites should not be created all over again, I'm also not sure if they are garbage collected at some time, maybe at the next scene change).

Comments

  • Thanks for the suggestion!
  • Would this ever affect the quality of the generated sprites?
  • As far as I understand the Docs on Sprites, using FullRect instead of Tight would only result in more pressure on the rasterizer (more transparent pixels being drawn which would otherwise be excluded by the tighter sprite mesh).
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.