I’m new to babylon so maybe I don’t fully understand how this engine works.
I put an HTML button that onlick activates a function which creates a line and attaches an action to it.
When I click the button the line is created but the action part isn’t working.
But if I call the function before starting the render loop it does work (a line is created and the action on it works).
@JohnK This only happens when pressing that HTML button.
If i create a mesh and assign OnPickTrigger action that does this, it works fine.
So I can’t recreate it in the PG (or can I?) but here is the code:
function createVector(x, y, z) {
var vec = new BABYLON.MeshBuilder.CreateLines("vector"+x+","+y+","+"z", {points: [new BABYLON.Vector3.Zero(), new BABYLON.Vector3(x, y, z)]}, scene);
vec.alwaysSelectAsActiveMesh = true;
vec.actionManager = new BABYLON.ActionManager(scene);
vec.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPointerOverTrigger, vec, "color", BABYLON.Color3.Red()));
vec.actionManager.registerAction(new BABYLON.SetValueAction(BABYLON.ActionManager.OnPointerOutTrigger, vec, "color", BABYLON.Color3.White()));
}
document.getElementById("vector-creation-btn").onclick = function() {
var inputs = document.getElementsByClassName("vector-creation");
createVector(inputs[0].value, inputs[1].value, inputs[2].value);
};
From your code, I expect it is a matter of context : where the “createVector” function is declared, it has access to “scene” for the MeshBuilder, but not anymore when called from your HTML button.
Do you have such an issue in your console ?