Inconsistent getMeshesByXXX functions return types

Hello there,

The getMeshesByXXX functions have inconsistant return types :

BABYLON.Scene.getMeshesByTags(tagsQuery: string, filter?: (mesh: BABYLON.AbstractMesh) => boolean): BABYLON.Mesh[]
BABYLON.Scene.getMeshesById(id: string): BABYLON.AbstractMesh[];

I don’t see any reason why getMeshesByTags should not return an AbstractMesh array. It can also cause issues with typescript’s type verification.

I think my question could also extend to getActiveMeshes which returns a SmartArray instead of a regular one.
BABYLON.Scene.getActiveMeshes(): BABYLON.SmartArray<BABYLON.AbstractMesh>

Should I open an issue about this ? If not, I’d like to know why things were made this way.

Welcome aboard!

getMeshesByTags should definitely returns an array of AbstractMesh (it’s even a bug)! Here’s the fix:

getActiveMeshes returns a SmartArray because it is the type of the underlying variable, and we don’t want to convert it to a true array for performance reason (in any case, it would be a breaking change to update it).

1 Like

Thanks for your answer and fix :slight_smile:

1 Like