[solved] setMaterial doesn't update my material

In my application, I want to be able to change the material used on my Spatial when a user clicks on it. I’m doing the following right now, but I noticed that my Spatial never changes visually. It is always just using the _defaultMaterial.

I tested the _selectedMaterial by setting that material on a Spatial when I first create and add it to _myNode and that works fine, but it seems like I can’t change the material during run time. In my console window I do see that my selected Spatial prints out that it is selected, but yet the material used to render is not changing. What is wrong?

_myNode.depthFirstTraversal( new SceneGraphVisitor() {
	public void visit( Spatial spat ) {
		if( spat == selectedGeo ) {
			spat.setMaterial( _selectedMaterial );
			System.out.println( "geo: " + spat.getName() + " is Selected" );
		} else {
			spat.setMaterial( _defaultMaterial );
			System.out.println( "geo: " + spat.getName() + " is NOT Selected" );
} );

What is printed ? with

System.out.printf( "geo: %s (%s) , mat : %s , is Selected : %S\n", spat.getName(), spat.getClass(), spat.getMaterial(), (spat == selectedGeo));

before and after if section.

PS: “Troubleshooting” is a better category for your topic

I couldn’t add that printf statement as you showed because Spatial.getMaterial is undefined. I therefore added a instanceof check to make sure that spat is of type Geometry and then I got an exception thrown when my code got hit. So then I wrapped everything up in an enqueue call and now everything is working. Thanks!