assetManager callback execution question in a class

It seems that none of my callbacks for a successful loading of an assetManager mesh are called. I assume it is because the method completes before they are needed? How would I re-write something like this to work. I am a bit stumped.

class aNode { public rootNode // Future easy reference to the root node for a class instance. Ideally this is what all transforms are applied to.
constructor(mediaPath: string, public nodeName: string, public fileName: string, assetManager, scene){
    this.rootNode = new TransformNode("rootNode", scene)
    this.rootNode.position = new Vector3(0, 0, 0)
    this.nodeName = nodeName
    this.makeMesh(mediaPath, fileName, assetManager, scene)

public makeMesh(mediaPath:string, fileName: string, assetManager, scene ){
    let meshPath = mediaPath + "models/" + fileName + "/"
    let meshName = fileName + ".gltf"
    let meshTask = assetManager.addMeshTask(fileName, "", meshPath, meshName)
    meshTask.onSucess = function(task){
        // I want to do some stuff here to the loadedMeshes, but this never seems to execute... why?
        this.rootNode = task.loadedMeshes[0]
            mesh.isVisible = true


var newInstance = new aNode(paramsGoHere)

One of Murphy’s laws say: “Where the success callback is not called, the error callback is called”:joy:
So, try with onError callback maybe you’ll get some mesages there.
And make sure you call


I didn’t see it in your code. Cheers!

I thought this IS murphy’s law!

So, neither onSuccess orOnFail seem to ever fire but assetManager.load() is being called by my main class, and the meshes load into the scene at 0,0,0.

I figured the only thing that would make sense is that the method makeMesh runs it’s course and finishes before AssetManager loads or does not load thus they never are able to fire. Though onProgress also does not really seem to load so :shrugs:.

I don’t see how to set things up to move onSucess or onFailure out of the class or method, so that it still exists when its time to be called - or really even verify what is happening. (Thus, I not only killed Murphy, but am actively peeing on his grave)

I may be going about this all wrong though. I would be curious to see how others are loading reusable assets.

I am using npm, assetsmanager is included. I don’t need something special for the callbacks though, right?

Oh. It is not too easy to tell you without a repo, but I’ll give one more try.
Do you have some console in onSuccess, or onError? If yes, they appear or they don’t?
There can be a scope issue too, ‘this’ from onSucces method is not your global ‘this’, you can try

meshTask.onSucess = (task) => {

or store it ourside of callback.

Yeah sorry about no repo. I did figure it out though. My this scope indeed did shift. Thanks for putting me on the right track.

1 Like