AbstractEngine and Engine conversion issues

This is part of my code, it gives an error in my project:

this.engine = new BABYLON.Engine(this._canvas, true, { premultipliedAlpha: false, preserveDrawingBuffer: true });
    this.scene = new BABYLON.Scene(this.engine);

When I use the purchase agent, I still get an error

    this.scene = new BABYLON.Scene(this.engine as BABYLON.AbstractEngine);


I want to know what I should do, looking forward to your reply

You should cast engine to Engine:

this.engine as BABYLON.Engine

The types should be compatible without issues.

cc @RaananW

would you be able to share the project? or a simple reproduction? would be interesting to see what the issue is. no casting should be needed TBH.

I’m encountering the same issues for Engine and ThinEngine types.

See here for repro.

It is not the same as here you are trying to upcast which is not possible.

In the first part of the thread we mentioned that a downcast should work. But as we did not see the code I wonder if there was not upcasting involved there as well.

Just my 2 cents, if the function is about checking the type, you can do something like this:

Engine type error repo | Babylon.js Playground (babylonjs.com)

AbstractEngine is not necessarily an Engine, but an Engine is always an AbstractEngine.

1 Like