[SOLVED] Problem with attaching animated model to bone attachmentNode

Hi friends

Getting this SEVERE exception when attaching an animated model to a bone attachment node :

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.UnsupportedOperationException: Material instances cannot be shared when hardware skinning is used. Ensure all models use unique material instances.
    at com.jme3.animation.SkeletonControl.controlRenderHardware(SkeletonControl.java:258)
    at com.jme3.animation.SkeletonControl.controlRender(SkeletonControl.java:299)
    at com.jme3.scene.control.AbstractControl.render(AbstractControl.java:135)
    at com.jme3.scene.Spatial.runControlRender(Spatial.java:756)
    at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:723)
    at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:733)
    at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:733)
    at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:733)
    at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:733)
    at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:733)
    at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:733)
    at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:712)
    at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1086)
    at com.jme3.renderer.RenderManager.render(RenderManager.java:1145)
    at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
    at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:193)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
    at java.lang.Thread.run(Thread.java:745)

this only happens when attaching animated model to BoneAttachmentNode

Can you please help with this error?

Thanks

setHardwareSkinningPreferred(false); in SkeletonControll fixed problem.
why that error just happens for attachmentNodes ?

That’s because the attachment node is modified by the skeleton. The root cause of the issue is that a model cannot be modified by two separate skeletons while using hardware skinning. If you want to have a model that as its own skeleton attached to another model with a skeleton, either you have to use software skinning by using setHardwareSkinningPreferred(false); like you did, or “hack” around it like I had to do.

2 Likes

Yeah, I think the scene graph tree based collection of skeletons and materials and stuff gets confused when the model has another child model.

If you want to keep hardware skinning, the other option is to not attach the child animated model at all but have a control that syncs it to the attachment node on update.

2 Likes

using the control idea seems good, going to do that.
Thanks for all helps

@pspeed using control idea saved me about 250 fps. :slight_smile:
before attaching child fps was 500 and after attaching child using control to sync, fps remained 500 whereas using software skinning dropped fps to 250.