#ThreeJS iPhone; cannot read properties of undefined (reading '0')

6 messages · Page 1 of 1 (latest)

autumn widget
#

This is the console error:
"IPhone.jsx?t=1742574779028:28 Uncaught TypeError: Cannot read properties of undefined (reading '0')"

And here's the code that breaks it:

 useEffect(() => {
    Object.entries(materials).map((material) => {
      // these are the material names that can't be changed color
      if (
        material[0] !== "zFdeDaGNRwzccye" &&
        material[0] !== "ujsvqBWRMnqdwPx" &&
        material[0] !== "hUlRcbieVuIiOXG" &&
        material[0] !== "jlzuBkUzuJqgiAK" &&
        material[0] !== "xNrofRCqOXXHVZt"
      ) {
        material[1].color = new THREE.Color(props.item.color[0]);
      }
      material[1].needsUpdate = true;
    });
  }, [materials, props.item]);

The code is copy/pasted from the github, all the imports are there, I can't figure out what's causing the issue though.

autumn widget
#

What're you thinking? A material not loading in before running?

#

commenting out the useEffect, refreshing the page, then bringing the useEffect back in works. I can click on various colors and the model will update.

It seems like the useEffect is causing no default color to be selected?

autumn widget
#

Ah I got it, in Model.jsx the model useState is "color" singular, I accidentally had "colors" plural.

lean sluice
#

Hi did you solve that problem?

autumn widget