PeterBacall

Something I've noticed recently is the CPU Spikes when changing attachments and having "repack" enabled. The game freeze for about a half second which makes it feel really "laggy" to swap weapons. Otherwise the game runs at a 100-200ish FPS.
Is this something that's normal/unavoidable/just how things work?

FYI: I have very little experience with Unity's profiler and writing "efficient code". Might be totally on me, plz be gentle :drunk:

Skärmavbild 2017-07-06 kl. 09.32.28.png
PeterBacall
Сообщения: 35

Pharan

Yes, repacking is will cause a pause, especially since Unity doesn't do it in a thread.
Ideally, you repack only once right before you don't need to switch attachments on your custom skin anymore.

I imagine it's worse, the more images you have, so you could make sure you're not including any attachments that are actually not needed.
Official Esoteric Assorted Furniture Cleaner and Teahouse | Check out the Spine Users Tumblr Blog: spine-users.tumblr.com
pharan.deviantart.com | pharantriestoanimatestuff.tumblr.com - - - Windows 10 - Spine-Unity.
Аватара пользователя
Pharan

Pharan
Сообщения: 4362

PeterBacall

How would you approach a system where I can switch weapons? I assume you wouldn't repack on each weapon swap, but maybe in the end of every map or something?

Thank you!
PeterBacall
Сообщения: 35

Pharan

Can you show a screenshot with Deep Profile enabled? It's right next to the record button.
Official Esoteric Assorted Furniture Cleaner and Teahouse | Check out the Spine Users Tumblr Blog: spine-users.tumblr.com
pharan.deviantart.com | pharantriestoanimatestuff.tumblr.com - - - Windows 10 - Spine-Unity.
Аватара пользователя
Pharan

Pharan
Сообщения: 4362

PeterBacall

Is this what you were looking for?
Skärmavbild 2017-07-07 kl. 03.30.24.png


ps. Sorry if my images are a bit dark

-- 13 Jul 2017, 08:08 --

Hi! Just wanted to check if there was any more updates to this one? Thanks!
PeterBacall
Сообщения: 35

Pharan

Can you expand the offending line? It should show more information in Deep Profile mode.

One measure that could be done is separate out GetRepackedSkin into its individual steps and do that over time instead of all in one frame, but that may require more management of it on your side. But first we have to determine if it's not simply because you're packing too many textures or some other thing Unity doesn't like.

Note that the repacking of the atlas itself here is done by UnityEngine, so we're limited by how much we can drill down.
Official Esoteric Assorted Furniture Cleaner and Teahouse | Check out the Spine Users Tumblr Blog: spine-users.tumblr.com
pharan.deviantart.com | pharantriestoanimatestuff.tumblr.com - - - Windows 10 - Spine-Unity.
Аватара пользователя
Pharan

Pharan
Сообщения: 4362

PeterBacall

Is this what you were looking for?
info.png
PeterBacall
Сообщения: 35

Pharan

Just offhand, you could try this caching version of AttachmentTools.cs : https://gist.githubusercontent.com/pharan/6d463452733f4e3d291c527b15473470/raw/f5af231cb5b1dbe959ed5cd7587e256ea48013e8/AttachmentTools.cs

I'm not sure how big of a difference it will make.
But in this version, you have to call SpriteAtlasRegionExtensions.ClearCache(); yourself any time after you're done repacking. Otherwise, extracted Textures will stay in memory. The first Repack operation will also be slow as it extracts the textures for the first time.

Note that this version will also not allow you to recycle old AtlasRegions, so you may have some unwanted sideeffects if you did some manual manipulation of existing AtlasRegions.
Official Esoteric Assorted Furniture Cleaner and Teahouse | Check out the Spine Users Tumblr Blog: spine-users.tumblr.com
pharan.deviantart.com | pharantriestoanimatestuff.tumblr.com - - - Windows 10 - Spine-Unity.
Аватара пользователя
Pharan

Pharan
Сообщения: 4362

PeterBacall

Thank you Pharan I will try this!
By the way: how important is it to repack for a PC/Mac/Linux game?
Or is repacking more of a mobile thing?
PeterBacall
Сообщения: 35

Pharan

The thing it really causes is using more materials, and more draw calls.
So it's not so much a desktop/laptop vs mobile thing as much as it is a scaling thing and a "rendering backend" thing.
Though you do hit the limit faster with lower-end mobile, just as you would with low-end desktop.

The more skeletons/characters your game has mix and match, the more important it is to repack. If most of them share the same base skeleton data, the more the caching change above will be a huge improvement.
And the more individual skeletons can share your repacked skin, the more benefit you get out of it.

And if multiple materials causes you to not be able to do certain things with rendering, or when it causes visual glitches, then it's also important to repack.
If you see no visual glitches or aren't doing any single-material-specific things, it shouldn't be a problem. Just add a Sorting Group component to your Spine GameObject if your Unity version is new enough.
Official Esoteric Assorted Furniture Cleaner and Teahouse | Check out the Spine Users Tumblr Blog: spine-users.tumblr.com
pharan.deviantart.com | pharantriestoanimatestuff.tumblr.com - - - Windows 10 - Spine-Unity.
Аватара пользователя
Pharan

Pharan
Сообщения: 4362

PeterBacall

Thank you for a well-written reply, appreciated!
Yes my Unity it is new enough, cheers!
PeterBacall
Сообщения: 35


Вернуться в Unity