0 like 0 dislike
Hi there,

I noticed in the profiler that there's a huge GC allocation when using a Shape Sampler with a Skinned Mesh Renderer inside Unity. At the moment i have 27.7 kb per frame for a 326 tris mesh, and 95.2 kb per frame for 3900 tris, logged inside LateBehaviorUpdate > PKFxFX.LateUpdate() .

Am I missing something ? The PkFX is super simple and juste sample the mesh position to emit particles. At the moment this features is totally unusable in production, as the GC is totally killing the framerate.

Thanks in advance.
by Poupi (160 points)
Hi Poupi,
Definitely does not sound normal at all. Also, the memory allocated for skinned mesh updates shouldn't depend on the number of verts, but on the number of bones (or, depending on what's really causing the allocations, on both. But the only data that should be transferred per mesh each frame from Unity to the PopcornFX plugin are the transforms of the bones).
I took a look at the code to try to see what was happening, apparently it could possibly free and reallocate each frame in some corner cases.

Apparently there's an option to force the update of the attributes each frame, and if that's activated, or if the FX was hot-reloaded, or if the mesh was changed, it will free the bones buffer that's supposed to be reused between frames, and will allocate another buffer to transfer the vertices, then it will free that and reallocate a buffer for the bones and retransfer the bones, and will keep doing that each frame.
I'll poke our Unity-plugin guys on that on monday, they should know better why it's done that way, and if it really was intentional, if it's a bug, if there's a workaround, etc.
After some more scrolling through code, this is triggered if you call "UpdateAttributes(true)" from C# (which should only be called when "StartEffect()" is called)
That's because we allocate one such scratch buffer for data transfer between C# <--> C++ once per mesh attribute sampler per instance of an effect.
So if you're starting 100 effects with the same mesh attribute sampler, it'll make 100 such allocations (!), just for data transfers, even if if could probably use a single scratch buffer.
But I'm not really up-to-date on the subtleties of the Unity plugin, so I'll double- check that with our Unity guys on monday.
just to be sure: you're not calling UpdateAttributes(true) manually each frame?
Hi Julien,

I'm not calling anything in code, there's just one camera, the skinned mesh and one instance of the PKFxFX component using the skinned mesh for sampling the position of the newborns.
The Unity plugin used is 2.9p3.

I created a simple repro project in case you need it :
[link removed]

Thanks !

1 Answer

1 like 0 dislike
Best answer
Hi Poupi,

There was indeed a memory issue.

Could you send me your invoice number at support_at_popcornfx_dot_com so I can send you a fixed version of the plugin ?

Cheers !
by Valentin (7.1k points)
Hi Valentin,

I found another issue with the skinned mesh sampling. When changing the dimensions, shape center or euler orientation there's another terrible allocation, I don't know if it's a bug or something related to how Popcorn handle these settings.

Thanks !