Methode spatial.setName(String name) have no effect on the geometry name?

Hello, i have been trying to change the name of some of my spatial in my 3D enviroment so i could put them in some category, so when i click on them the system actully know what he is clicking on (Ennemy, ally, NPC, ect) But when i try to set the name using the setName fonction it do not work.

Am using something like this to get the name of what i was clicking on :
String hit = results.getCollision(i).getGeometry().getName() ;

After some test i realise that if i took an actual Geometry item and i had it name in the constructor, it would work, and the method set name actully work to. But as am not getting an error or a null on my hit String when am clicking on a spatial (am usaly getting something like Plane1) then i should be able to get the string name of the Geometry itself, and change it. But i don’t see any method to do that or any way i could change the collision method way to get the name out.

Any suggestion?

setName() definitely works. You must be setting it on a different geometry.

At any rate, this is the most cumbersome way of detecting hits because it completely fails if your object has more than one geometry (which is what I suspect is going on in your case).

Set some user data on the model in the same way you’ve been setting the name. Then when geometry is clicked, search up through its parents until you find the user data you expect. Something like myModel.setUserData(“type”, “NPC”)

This has been covered about 500 times on the forum before so you can probably find some posts if you search diligently. I’ve posted code a few times before.

1 Like

Yeah, i totally agree with pspeed. And one more thing. Which number are you using in results.getCollision(i)? You know that, in programming, 0 it’s in the real life 1, right?

To make more simple, you can just detect the closest collision:

[java]String hit = results.getClosestCollision().getGeometry().getName();[/java]

Im not english, there may be mistakes on the text.

Alright thanks for the help, i did find the code you where talking about and modefy it a little bit so it would fit my need. the basic look a little bit like this

for( Spatial s = results.getCollision(i).getGeometry(); s != null; s = s.getParent()) {
if( s.getUserData(“ID”) != null )
//Do some more stuff

Ps : ya i know for the 0 thing, am new but not that much :stuck_out_tongue: Anyway for the moment i only use the collision 0, but soon i want the program to consider every collision and offer the user the choice of the collision he want to consider, so if a lot a player are on one spot and all you need is to use that spot (cause it is a door or something) you would still be able to do it