# Material class throws an error in the example provided in the documentation

**URL:** <https://community.cesium.com/t/material-class-throws-an-error-in-the-example-provided-in-the-documentation/28980>\
**Category:** CesiumJS\
**Created:** [December 29, 2023, 8:51am UTC](https://community.cesium.com/t/material-class-throws-an-error-in-the-example-provided-in-the-documentation/28980 "2023-12-29T08:51:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![s3xysteak](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/s3xysteak/32/19939_2.png) [@s3xysteak](https://community.cesium.com/u/s3xysteak)\
**Post date:** [December 29, 2023, 8:51am UTC](https://community.cesium.com/t/material-class-throws-an-error-in-the-example-provided-in-the-documentation/28980/1 "2023-12-29T08:51:28Z")

</div>

Here is the code of a example in the [document](https://cesium.com/learn/cesiumjs/ref-doc/Material.html).

```javascript
polygon.material = new Cesium.Material({
  fabric: {
    type: 'Color',
    uniforms: {
      color: new Cesium.Color(1.0, 1.0, 0.0, 1.0)
    }
  }
});

```

And here is a mini repo:

```javascript
  const viewer = new Cesium.Viewer(container)

  const entity = viewer.entities.add({
    polygon: {
      hierarchy: Cesium.Cartesian3.fromDegreesArray([
        -108.0, 42.0, -100.0, 42.0, -104.0, 40.0
      ]),
      material: new Cesium.Material({
        fabric: {
          type: 'Color',
          uniforms: {
            color: new Cesium.Color(1.0, 0.0, 0.0, 0.5)
          }
        }
      })
    }
  })

```

In cesium version `1.112.0`, it throw error `"Unable to infer material type: [object Object]"`

---

<div class="post-metadata">

**Author:** ![Marco13](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/marco13/32/2757_2.png) [@Marco13](https://community.cesium.com/u/Marco13)\
**Post date:** [December 29, 2023, 1:23pm UTC](https://community.cesium.com/t/material-class-throws-an-error-in-the-example-provided-in-the-documentation/28980/2 "2023-12-29T13:23:15Z")

</div>

This error is thrown due to the difference between the ‘Entity API’ and the ‘Primitive API’.

The details are subtle (and I’ll frankly admit that I wouldn’t claim to have a perfectly clear picture here either), but the key differences are explained at the beginning of [Creating Entities – Cesium](https://cesium.com/learn/cesiumjs-learn/cesiumjs-creating-entities/)

As an attempt to boil it down to the most relevant part:

You are trying to create an _Entity_. And when you want to create an _Entity_, then the `material` that you are passing in there, via the `material` property, may not be a `Cesium.Material`. It has to be a [`Cesium.MaterialProperty`](https://cesium.com/learn/cesiumjs/ref-doc/MaterialProperty.html).

So if you want to assign a simple color material (_property_) to that entity, then the code would be

```auto
const viewer = new Cesium.Viewer("cesiumContainer");

const entity = viewer.entities.add({
  polygon: {
    hierarchy: Cesium.Cartesian3.fromDegreesArray([
      -108.0, 42.0, -100.0, 42.0, -104.0, 40.0
    ]),
    material: new Cesium.ColorMaterialProperty(
      new Cesium.Color(1.0, 0.0, 0.0, 0.5)
    )
  }
});

```

---

<div class="post-metadata">

**Author:** ![s3xysteak](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/s3xysteak/32/19939_2.png) [@s3xysteak](https://community.cesium.com/u/s3xysteak)\
**Post date:** [December 29, 2023, 1:40pm UTC](https://community.cesium.com/t/material-class-throws-an-error-in-the-example-provided-in-the-documentation/28980/3 "2023-12-29T13:40:29Z")

</div>

> [@s3xysteak](#):
>
> `polygon.material = new Cesium.Material`

That was a misunderstanding…Document said `polygon.material = new Cesium.Material` so I thought the polygon here means Entity.polygon.😣
