getMeshByName does not function

Hello I cannot understand how to access a mesh by its name, can somebody help me?

Here is my code, I just want to access an imported mesh, name it and remove from the scene, that simple, but I can’t:

There are some other topics with the similar name but none of them helped me.

Hi @meo and welcome to the forum.

This is because line 18 is executed before the skull is loaded and named.

Inside the render loop you can check for its existence before removing, etc

otherwise any dealings you have with it must be inside the loader

1 Like

thanks for the solution.

Hello JohnK, your answer solved my problem partially but not fully. What I want actually to do is when a website visitor enters a button I want to delete a STL model from scene and add a new one to scene.

But I cannot access the model or the mesh by its name. I tired this solution but it did not work out, I could not access the the old mesh:

Hi @meo and warm welcome from me.

Function sequence is also important.

1 Like

Thank you, it is a solution, but again it did not solve my whole problem.

I want to have a html button like this:

“Rotate the Object”

for example and want to access some of the meshes through the function rotate1(). Actually I want to delete last object and load another one but let say rotate it. It is easier to check whether it works.


This is just an example

Do your homework :wink:

1 Like

Hello, thank you but I want to have an html button not a button inside the scene. Like:

<button type="button" onclick="removeObj()">Remove</button>

the function removeObj() should be outside the “createScene” function.

I can do that with three.js but I have problem with it shaders therefore I moved to BJS.

I found this topic, but I could not understand fully: does it really mean that is impossible to reach scene elements through html ui even like simple buttons?

First of all if you have a new question start a new topic. You are much more likely to get an answer to your question. Particularly if your first question is solved.

Yes you can use an HTML GUI
Simple example Babylon.js Playground
or dat.gui
or CastorGUI - Babylon.js Documentation

Babylon.GUI is necessary if you are using VR or you want the GUI to be within the 3D world not just overlaying it.

1 Like

Thank you for your response, I will take your advice next time according to open new topic.

I found yesterday to the solution of CastorGUI but its side is not reachable: