felixmariotto / three-mesh-ui

⏹ Make VR user interfaces for Three.js
https://felixmariotto.github.io/three-mesh-ui/#basic_setup
MIT License
1.26k stars 134 forks source link

scene.getObjectsByName not working #248

Closed jmpedrosa closed 1 year ago

jmpedrosa commented 1 year ago

hi, threejs scene method getObjectByName is returning undefined, I realized that although I'm setting the name attribute, either in the block constructor or later on by calling someBlock.set({name:"someName"}) the attribute is not being set.

Is there any other way I could reference the objects on the scene whitout storing them appart?

Thank you for your time.

swingingtom commented 1 year ago

Hi @jmpedrosa, On version 6.x.x MeshUIComponent.set({}); only wrap its own properties. Whereas in 7.x.x it has a default handler that set its property.

In your case, simply go with :

const block = new ThreeMeshUI.Block({...});
block.name = "myblock";
//[...]
const blockByName = scene.getObjectByName("myblock");

Here is a sandbox sample : https://codesandbox.io/s/name-property-7vn09m?file=/src/sandbox.js

jmpedrosa commented 1 year ago

thanks, sorry for the late reply. I've been really bussy.