How to remove child object that is bound to the parent's animation clip?

How to remove child object that is bound to the parent's animation clip?
0.0 0



I’m currently dealing with animation tool from Cocos Creator now. I am making a shoot em up game, and I am utilizing the animation clip component attached to a node called Wave, to animate a fleet of enemy ships that are children of that node.

Each of the enemy ship under the Wave node animates slowly from top to bottom, marching. At that moment, these enemy ships can get hit by player’s bullet as long as they’re on the screen.

The problem is, when an enemy ship gets hit and destroyed (using node.destroy), it throws an error (shown below) where the position is null, which is obvious because the ship is gone but the animation clip on Wave node is still seeking for an object that has been removed.

Uncaught TypeError: Cannot read property 'x' of null
at cc_Node.setPosition (CCNode.js:1564)
at cc_SampledAnimCurve._applyValue (animation-curves.js:121)
at cc_SampledAnimCurve.sample (animation-curves.js:192)
at AnimationState.22.proto.sample (types.js:390)
at AnimationState.22.proto.update (types.js:283)
at AnimationAnimator.16.animProto.update (animators.js:28)
at CCClass.update (animation-manager.js:20)
at TheClass.update (CCScheduler.js:401)
at TheClass.mainLoop (CCDirector.js:1467)
at callback (CCGame.js:572)

I honestly don’t know how to properly deal with this in the code, because it’s all done in the editor. How do I make the Wave’s animation clip to stop animating a child object that doesn’t exist anymore but still run other objects like normal? Or should I just make the opacity of the object to 0 (after individual “destroyed” animation clip) instead of destroying it and wait until the wave is finished, then destroy the whole wave by the end of the whole wave animation? Or is it not possible, that I should individually make an animation clip per object and make a scheduler?

Please help and let me know if you have a better solution/best practice.