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!
JohnK
June 11, 2020, 11:34am
2
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
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.
2 Likes
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
JohnK
June 12, 2020, 3:34pm
4
Don’t see the problem, no cloneB in sight.
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).
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
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
Any help or suggestions would be greatly appreciated
JohnK
June 18, 2020, 8:59am
7
Not a metadata problem as such. Covert sphereInstance.metadata.test to a string using
sphereInstance.metadata.test.toString();
or by concatenating a string as in this PG 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.
1 Like
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 !