'ThreeJS returning undefined whenever I try to get a value from UserData
Ive spent so long trying to figure out why I can't get a value from UserData. I think my code works fine, but I'm just lost.
The raycast code is pretty simple.
const interactIntersects = raycaster.intersectObjects( flags, true );
if (interactIntersects.length > 0)
{
console.log(interactIntersects[0].object.userData.id);
}
I can't figure out why it keeps giving me the undefined value. I was thinking it mightve been the insertion of the data itself, but when I checked it returned the values. (Checking in the place where its being created)
export function createFlag(flag_id, web, desc, x, y, z, orx, ory, orz)
{
const fbxLoader = new FBXLoader()
fbxLoader.load('flag.fbx', (object) =>
{
object.scale.set(.003, .003, .005);
scene.add(object)
object.position.set(x, y, z)
object.rotation.set(orx, ory, orz);
object.userData = { id: flag_id };
console.log(object.userData.id);
flags.push(object);
});
createModal(flag_id, web, desc);
}
Can anyone help? Thanks in advance.
Solution 1:[1]
Found out you cannot set userData to Imported objects.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kroover |
