After deleting the child object, the code cannot be executed

After importing the fbx model, I want to delete the car object.

“if (“Vehicle”)) object.remove(child);”
If the “Code” code is not executed, the log “2222222222” is displayed.

However, when this “Code” is executed, “22222222” is not displayed.

Removing or adding objects while using Object3D.traverse() is not supported. The method assume the object hierarchy is not changed.

Try to rewrite your code like so:

const vehicle = object.getObjectByName( 'Vehicle' );
const parent = vehicle.parent;
parent.remove( vehicle );

Is there a way to search by name containing “Vehicle”?
The object names are “Vehicle_01”, “Vehicle_a_02”.

I found a way.
I was worried because I couldn’t speak English well, but thank you very much for letting me know easily with the code.

1 Like