Making new material vs setColor

Hello, I am just starting and have following issue with 8th step (https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_picking): I am trying to change color of cube which was hit. Unfortunately, that

[java]

results.getCollision(i).getGeometry().getMaterial().setColor(“Color”, ColorRGBA.Gray);

[/java]

cause “java.lang.IllegalArgumentException: Material parameter is not defined: Color”.



When I make new Material, everything seems to be fine:

[java]

Material newmat = new Material(assetManager,

“Common/MatDefs/Misc/Unshaded.j3md”);

newmat.setColor(“Color”, ColorRGBA.Gray);

results.getCollision(i).getGeometry().setMaterial(newmat);

[/java]



Why first option fail? Thanks in advance.



PS. My first post, so welcome everybody!

It is possible that you are picking something else, and that thing does not have the Unshaded material.

What you can do to test is to get the name of the geometry you picked, and the name of the material:

[java]

System.out.println(results.getCollision(i).getGeometry().getName());

System.out.println(results.getCollision(i).getGeometry().getMaterial().getName());

[/java]

Then confirm they are what you expected.

You can also print out all of the material parameters when you hit it with:

[java]

System.out.println(results.getCollision(i).getGeometry().getMaterial().getParams());

[/java]



Remember that getCollision(i) is not necessarily the closest geometry. You want to use:

[java]

results.getClosestCollision();

[/java]

1 Like

Thanks for help Sploreg. It seems problem was trying change color of golem (my ray often crossed his body, after cube) and as I suppose there is no color into golem material.

Using [java]getClosestCollision()[/java] eliminate problem completly - unless I aim on golem of course.

The golem is probably using the lighting material.

Look for Lighting.j3md. That is a material definition file that shows you what parameters it accepts.