Unity Toolkit - Converting from AbstractMesh to Mesh


I am having trouble trying to highlight a mesh like in this playground example using typescript in Unity.

Here is my typescript:

module PROJECT {
export class Highlight extends BABYLON.MeshComponent {

    owner: BABYLON.AbstractMesh;
    scene: BABYLON.Scene;
    public constructor(owner: BABYLON.AbstractMesh, scene: BABYLON.Scene, tick: boolean = true, propertyBag: any = {}) {
        super(owner, scene, tick, propertyBag);
        this.owner = owner;
        this.scene = scene;

    protected ready() :void {
        // Scene execute when ready

    protected start() :void {
        // Start component function
        var hl = new BABYLON.HighlightLayer("hl", this.scene);

        var material1 = new BABYLON.StandardMaterial("mat1", this.scene);
        material1.diffuseColor = new BABYLON.Color3(1, 1, 0);

        //Apply Highlight layer to box
        hl.addMesh(this.owner, BABYLON.Color3.White());


The problem is, .addMesh() only accepts a Mesh type and not an AbstractMesh type. Is there a way to convert an AbstractMesh or another way to accomplish highlighting?

Any suggestions would be great. I’m still very new to Babylon.js and the documentation for the Unity exporter isn’t extremely detailed, so I appreciate your patience.


Unsure if it is the best way to do it, but to get around Typescript compiling, you can do (variable as BABYLON.Mesh) to tell it that it will be a BABYLON.Mesh type.

I was thinking that might work. However, I can’t verify if it does until I figure out how to enable stencil using the exporter. Any ideas on how to do that? I checked under the default engine options, but I didn’t see anything…

Nevermind, I figured it out. Stencil was enabled, it was just a problem with the model I was using. Thanks for the help!