It's a common scenario where accessing model properties before it loads causes issues. To solve this, you need to listen for the model-loaded
event on components like gltf-model and obj-model. Here's an example:
<script>
AFRAME.registerComponent("modelhandler", {
init:function() {
this.el.addEventListener("model-loaded", (e)=>
let child = obj.getObjectByName( "Cylinder", true );
console.log(child);
});
}
</script>
<a-entity gltf-model="url(/path/to/model.gltf)" modelhandler></a-entity>
If that doesn't work, you can try setting a timeout of 5 seconds before attempting to grab child objects. This way, you'll know if the issue is related to loading times.
setTimeout(()=>{
let child = obj.getObjectByName( "Cylinder", true );
console.log(child);
}, 5000});
This approach should help resolve any issues related to accessing model properties too early.