I’m working on a little project that will involve interaction with 2 rigged characters. After the interaction with character1 it will no longer be needed, so I want to delete it to get rid of 30 bones and associated meshes and animations. Here is my effort so far :
It is driven by a simple GUI button. But before you click the button, open the Inspector and view the nodes. Now click the button, an animation plays then a sound with a second animation. When the sound finishes, I try to delete the meshes (8 of them) associated with the rig - but only 4 get deleted. The button reappears and can be clicked again. A further two meshes are deleted. Repeat until all meshes are gone then the skeleton disappears too (watch the Inspector to see things vanishing).
What I don’t understand is why only half the meshes are disappearing on that first click. The “allmeshes” variable contains contains 8 meshes at the start. So why only 4 meshes deleted by the loop at lines 65-67?
My second question is when the skeleton is deleted do the bones, animation frames and animation ranges get deleted?
Any help for this crap coder is greatly appreciated.
Ohh by the way, if using Chrome to view the little no sound icon will pop up. Click it and rerun the the PG.
You can also open the console to view what is happening
The problem is that when a mesh is disposed it is removed from the scene’s array of meshes, so the for loop’s next index will be one too large. One way to fix it is to decrement i after disposing each mesh, another way is using a while loop like below.
It seems another issue is that interacting with the canvas doesn’t seem to be a “user gesture” worthy of enabling audio, but after clicking on the playground’s Run button then audio works…
EDIT: sorry LOL the audio not working when the PG first loaded through me for a loop, I wasn’t sure what was going on at first…
Hmm, regarding what happens to the bones when the skeleton is disposed, it looks like the answer is nothing? Maybe @Deltakosh or @sebavan can confirm if it’s needed, but it seems like Skeleton’s dispose method should set this.bones = []; so that the references to the bones are dropped?
@Blake : Yes I was wondering about that, and the animation with each bone and the “ranges”. And when I consider the second character which will not be encountered for a while, is it possible to disable all that stuff?
But doesn’t the bone maintain a reference to the skeleton as well which is never nulled (.skeleton)? Or is not a problem to have the circular reference if both are otherwise unreachable?
EDIT: from a little research it seems that memory leeks from circular references were more of a problem with older browsers, not so much any more…