# Get Mesh Metadata Value

**URL:** <https://forum.babylonjs.com/t/get-mesh-metadata-value/11596>\
**Category:** Questions\
**Created:** [June 11, 2020, 12:26am UTC](https://forum.babylonjs.com/t/get-mesh-metadata-value/11596 "2020-06-11T00:26:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anderson34](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anderson34](https://forum.babylonjs.com/u/Anderson34)\
**Post date:** [June 11, 2020, 12:26am UTC](https://forum.babylonjs.com/t/get-mesh-metadata-value/11596/1 "2020-06-11T00:26:15Z")

</div>

With the code below, I am able to click on an mesh and retrieve its name.

```
  scene.onReadyObservable.add( function(){
    
        cloneB.isPickable = true;
        cloneB.actionManager = new BABYLON.ActionManager(scene);

        cloneB.actionManager.registerAction(
            new BABYLON.ExecuteCodeAction(
                BABYLON.ActionManager.OnPickTrigger, function() {
                     
                    text1.text = cloneB.name;

                }
            )
        )
    
});

```

However, when I use the same code to retrieve **mesh metadata values** , the scene crashes 🤔  
Example: text1.text = **cloneB.metadata.energyValue**

I think I need to “call” or “get” that value first, but I haven’t found anything in the documentation for this.

Thanks in advance for any help or suggestions!

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [June 11, 2020, 11:34am UTC](https://forum.babylonjs.com/t/get-mesh-metadata-value/11596/2 "2020-06-11T11:34:23Z")

</div>

As usual please post a simplified PG with the issue not just some code. If your mesh has metadata it should retrieve it.

[https://www.babylonjs-playground.com/#52JLRQ](https://www.babylonjs-playground.com/#52JLRQ)

You can get the metadata from sphere because it has been set but not possible from ground where it has not been set.

If you think you have set the metadata for cloneB somewhere then your code above is running before that setting occurs.

---

<div class="post-metadata">

**Author:** ![Anderson34](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anderson34](https://forum.babylonjs.com/u/Anderson34)\
**Post date:** [June 11, 2020, 9:01pm UTC](https://forum.babylonjs.com/t/get-mesh-metadata-value/11596/3 "2020-06-11T21:01:58Z")

</div>

Hello again @JohnK, and thanks for taking a look at this. I forgot to add that the metadata changes over time, so it’s not a constant value. Here’s a PG where sphere2 should add 1 to metadata.test whenever it collides with a border.

[https://www.babylonjs-playground.com/#SD6H29#3](https://www.babylonjs-playground.com/#SD6H29#3)

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [June 12, 2020, 3:34pm UTC](https://forum.babylonjs.com/t/get-mesh-metadata-value/11596/4 "2020-06-12T15:34:48Z")

</div>

Don’t see the problem, no cloneB in sight.

---

<div class="post-metadata">

**Author:** ![Anderson34](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anderson34](https://forum.babylonjs.com/u/Anderson34)\
**Post date:** [June 12, 2020, 9:34pm UTC](https://forum.babylonjs.com/t/get-mesh-metadata-value/11596/5 "2020-06-12T21:34:21Z")

</div>

I actually made a new PG, but it’s the same basic issue, which is getting metadata values that are actively changing over time. So for the PG above, I would want to display how many times a **sphere2 clone** collides with a border (stored in sphere2.metadata.test).

---

<div class="post-metadata">

**Author:** ![Anderson34](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anderson34](https://forum.babylonjs.com/u/Anderson34)\
**Post date:** [June 17, 2020, 11:36pm UTC](https://forum.babylonjs.com/t/get-mesh-metadata-value/11596/6 "2020-06-17T23:36:19Z")

</div>

Hello everyone,

I’m still having trouble solving this problem, so I created a PG that will hopefully better illustrate what I’m trying to achieve:

[https://www.babylonjs-playground.com/#PUUV79](https://www.babylonjs-playground.com/#PUUV79)

In the PG above, when you click on a sphere, its name will be displayed.

However, when I add the line to display metadata (text1.text = sphereInstance.metadata.test;), the scene crashes (see PG below). 🤔

[https://www.babylonjs-playground.com/#PUUV79#1](https://www.babylonjs-playground.com/#PUUV79#1)

Any help or suggestions would be greatly appreciated 😃 👍

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [June 18, 2020, 8:59am UTC](https://forum.babylonjs.com/t/get-mesh-metadata-value/11596/7 "2020-06-18T08:59:43Z")

</div>

Not a metadata problem as such. Covert sphereInstance.metadata.test to a string using

```javascript
sphereInstance.metadata.test.toString();

```

or by concatenating a string as in this PG [https://www.babylonjs-playground.com/#PUUV79#2](https://www.babylonjs-playground.com/#PUUV79#2) you will get results in the text block but not sure they are what you expect.

As I do not want to second guess about what you expect in the text block please post your expectations.

---

<div class="post-metadata">

**Author:** ![Anderson34](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Anderson34](https://forum.babylonjs.com/u/Anderson34)\
**Post date:** [June 18, 2020, 9:36pm UTC](https://forum.babylonjs.com/t/get-mesh-metadata-value/11596/8 "2020-06-18T21:36:34Z")

</div>

That’s exactly right, thanks! I knew the metadata was there, I just didn’t know that it had to be converted to a string first.

Thanks again @JohnK! 😃 👍
