aframe error: Entity.setObject3D was called with an object that was not an instance of THREE.Object3D Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of aframe error: Entity.setObject3D was called with an object that was not an instance of THREE.Object3D without wasting too much if your time.

The question is published on by Tutorial Guruji team.

hello i’ve tried to add a mesh to my aframe component, but i receive a strange error also with a very simple code like this

AFRAME.registerComponent('mysquare', {
      init: function(){
        var el = this.el; 

        var box = new THREE.BoxGeometry(40, 5, 40);
        var boxMesh = new THREE.Mesh(box);
        boxMesh.position.set(25, 0, 25);
        el.setObject3D("mesh", boxMesh);

      }
    });

home.html

<ion-content>
      <div></div>
      <a-scene embedded>
         <a-entity mysquare></a-entity>
       </a-scene> 
</ion-content>

error message

Error: Entity.setObject3D was called with an object that was not an instance of THREE.Object3D.

i tried also the add function but i receive the same message. how is possible?

i develop my app with ionic 2 + aframe v.0.7.1. i’ve tried also with the 0.5.0 version but i have the same problem

Answer

finally i’ve solved the problem without include directly the threejs library.

my import section was this

import * as THREE from 'three';
declare var AFRAME;

i’ve deleted the first import and now all it’s okay. now i can create a 3d object in this mode

el.setObject3D("mesh", new AFRAME.THREE.Object3D());
We are here to answer your question about aframe error: Entity.setObject3D was called with an object that was not an instance of THREE.Object3D - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji