attachChild by name

Hello,



I’m new to programming in general, and this is my first attempt at reaching out for help, so please excuse if I stumble through the process.



What I’m trying to do:

Create a grid of spatials that are generated by procedure.



What I’d like to be able to do:

Attach a child by name (string).



Problem:

I only see options for attaching children by spatial (not string). This is a problem for how I am attempting to do it because I am generating the spatials from the same “create spatial” line of code then renaming them with variables in a string, which makes them only callable by name. The spatials are not recognized by the system as existing since they are not technically generated till the code runs, so I get errors in the editor. I’ve also tried using the variable generated string name, but I can’t attach a child by string.



I see that I can detach a child by name (string), but I’m not seeing an option to attach by name. I also had the thought that if I could return a spatial by name it would work too, but I’m not seeing anything like that either.

I’m also not sure that i’m going about this the proper way. Any nudges in the right direction would be appreciated.



Thank you,

Cym



gridX = 0;

gridY = 0;

gridXmax = 5;

gridYmax = 5;

gridCurrent = 0;

gridTotal = gridXmax * gridYmax;

gridXfloat = 0;

gridYfloat = 0;

gridZfloat = 0;

Vector3f currentvector = new Vector3f( gridXfloat, gridYfloat, gridZfloat );



while (gridCurrent < gridTotal) {

Spatial genericTile = assetManager.loadModel(“Models/Tiles/Grass1/grass1.obj”);

genericTile.setLocalTranslation(currentvector);

genericTile.setName((“tile” + gridX + “x” + gridY));

grid.attachChild();



gridCurrent ++;



if (gridX < gridXmax) {

gridX ++;

}



if (gridY < gridYmax) {

gridY ++;

}

You just need to attach, the name is stored in the spatial…?

Maybe i’m misunderstanding how spatials work.



If i rename a spatial with the string: “tile” + gridX + “x” + gridY



I can’t attach the spatial by that string: grid.attachChild((“tile” + gridX + “x” + gridY));

because it tells me I can’t use type “string”.



And although the name of the spatial is actually “tile1x1” (when gridX = 1 and gridY = 1), because that spatial name doesn’t exist until the variable string (“tile” + gridX + “x” + gridY) is ran, the editor doesn’t know and even if I put “tile1x1” in for the spatial it returns an error “cannot find symbol”.

As in:

gridX = 1;

gridY = 1;

Spatial genericTile = assetManager.loadModel(“Models/Tiles/Grass1/grass1.obj”);

genericTile.setName((“tile” + gridX + “x” + gridY));

grid.attachChild(tile1x1);







What I might not know is if when I rename a spatial here:

Spatial genericTile = assetManager.loadModel(“Models/Tiles/Grass1/grass1.obj”);

genericTile.setName((“tile” + gridX + “x” + gridY));



I assumed that this made spatial “genericTile” no longer available because genericTile changed to my variable string (“tile” + gridX + “x” + gridY)

[java]

Spatial genericTile = assetManager.loadModel(“Models/Tiles/Grass1/grass1.obj”);

genericTile.setName((“tile” + gridX + “x” + gridY));

grid.attachChild(genericTile);

genericTile = grid.getChildNamed(“tile” + gridX + “x” + gridY);//Does it return the genericTile properly?

[/java]