java.lang.UnsupportedOperationException: Material instances cannot be shared when hardware skinning is used. Ensure all models use unique material instances

Hi there,

I’m upgrading my older JME applications to JME 3.1.

Because hardware skinning is enabled I need to be able to over come a slight issue.

The issue is on the line:

entity.model.clone(true);

I imagine it is cloning the material as well and adding the same material and the sharing of the material is causing the error.

Whats the quickest way to create a copy of a Node without running into this issue?

You left 90% of the useful information out of the exception.

It’s unlikely that the included line is the real problem since that forces the materials to be cloned instead of shared. Unless that line is actually in the stack trace that you didn’t include… but I can’t see that.

Here is the entire Exception:

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.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)

I had assumed it was that line because it the error occurred when that method was being run and I had seen a previous unsolved forum post about using the clone method resulting in material issues.

If the entire stacktrace is more helpful you can take a look.

Thanks for reading.

Well, the exception shows that the error happens during rendering… not when that method is being run. Or did you mean that before adding that method that the error didn’t happen?

clone(true) should clone the material. A cloned material is not shared. Sometimes the error is detecting the wrong thing, though.

Best way to move forward would be to put together a simple single class test case illustrating the issue.

I did a bit more testing.

Turns out it isn’t that line. I’ll do a bit more work to see if I can find out exactly where the problem is.

EDIT: Okay the issue is when I attach any model to an attachment node of a bone. The clone thing is not an issue.

Now the question is, why would I be unable to attach this model to the bone attachment node?

I can attach it to the model itself or the node that holds the model. Just not the bone part.

Because of the way the animation works it assumes that there will only be one animatable thing in that part of the subgraph. As soon as you attach another node that has animation to it as a child then things get all confused.

The only way to ‘attach’ an animated node as the child of another animated node is to not actually attach it… but to attach a surrogate node and then use some kind of control to keep the real node in the same position.

1 Like

Right, thanks for that information. That’s a little deeper than my personal knowledge goes on the way rendering works with hardware skinning.

I imagine just tracking and updating the position via a control as you suggested would do fine.

Thank you for the help.