Inconvertible types: Spatial to Node


I am currently working through the tutorial section and i found in some tutorials (for example tutorial 7) that my the jMonkey Platform displays this error message if i copy the tutorial code:

[java]inconvertible types

found : com.jme3.scene.Spatial

required: com.bulletphysics.collision.broadphase.Dbvt.Node

player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");[/java]

If i change from Node to Spatial and remove the cast it works (in that certain case) but in other cases the code messes up if i change the type.

So what am i doing wrong? I use the jMonkeyPlatform-Alpha4.

Thank you for your help

Spatial is Node’s parent class, so a Node is always a Spatial, but a Spatial is not always a Node.

usually when you load a mesh.xml file the return is not a Node, but a Geometry.

So to be sure, use Spatial, because it’s the parent class of both Geometry and Node.

If you have to use a Node then, check the type (instanceof) and cast it.

Or, create a new Node, and attach the loaded Spatial to it.


While everything nehon said is true…

In this case, the error is because you are importing the wrong Node class. The bulletphysics Node is not even remotely compatible to Spatial or Node… and so you get the compile error.

What Nehon is talking about are the runtime errors you will likely get.


Thank you, changing the import fixed that problem.