Issues with updateCallback

Hello @MajorMeerkatThe3rd ,
I am experiencing an issue while using updateCallback function.I basically have animation data for different objects like doors and drawers which needs to be added to the respective nodes of doors and drawers.As the data added gets cleared whenever a paramter updates so i am using the updateCallback functionality so that data gets automatically assigned whenever the output nodes of doors and drawers are updated.The animation data comes as output and when i try to access it inside the updateCallback it shows undefined but when i check the console.log for the data its there.The probable issue i could figure out is that the updateCallback gets called before the door and drawer outputs are able to update and that is why there is no data.
I have attached the code for reference .

 const output=Session.getOutputByName(anim.outputName)[0];
                
          output.updateCallback=(nodes?:ITreeNode)=>{
          const node = nodes?.getNodesByName(anim.outputName.replace(/\s+/g, "").toLowerCase())[0]!;
              //console.log(node,"nonon")
              if(node){
                  if(anim.type === "translation"){
                        const animationOutput = Session.getOutputByName(anim.animationDataName)[0];
                    console.log(animationOutput,"outputput")

                        const outputData = animationOutput.node!.data.find((d) => d instanceof SessionOutputData)!;
                        if(!outputData){ //This data is not present
                            return ;
                        }
                        console.log(outputData)
                        const animationDefinition = (outputData as SessionOutputData).responseOutput.content![0].data as AnimationDefinition;
                      node.children.forEach((n)=>{
                              n.data.push(new InteractionData({ hover: true, select: false }));
                             let name=n.name;
                            const animationDef = animationDefinition[name];
                            console.log(animationDef)
                              const matrix = n.nodeMatrix
                              const x = matrix[12];
                              const y = matrix[13];
                              const z = matrix[14];
                              const start = { x, y, z};
                              const times = animTime;
                              const values = [
                                  start.x, start.y, start.z,
                                  ...(animationDef.vector as number[]),
                                   start.x, start.y - 50, start.z,
                                  start.x, start.y, start.z
                              ];
                      
                              const tracks: IAnimationTrack[] = [{
                                  times: times,
                                  node: n,
                                  values: values,
                                  path: "translation",
                                  interpolation: "linear"
                              }];
                      
                              const data = new AnimationData(n.name, tracks, 0, animTime[animTime.length-1]);
                              n.data.push(data);
                              n.updateVersion();
                            //   data.startAnimation();
                            //   data.repeat=true
                              Viewport.update();
                      })
                  } else if(anim.type === "rotation"){
                    const animationOutput = Session.getOutputByName(anim.animationDataName)[0];
                    //console.log(animationOutput,"outputput")
                    if(animationOutput.node){
                        const outputData = animationOutput.node!.data.find((d) => d instanceof SessionOutputData)!;
                        const animationDefinition = (outputData as SessionOutputData).responseOutput.content![0].data as AnimationDefinition;
                        //console.log(animationDefinition,'deffef')
                        node.children.forEach((n,i:number)=>{
                            //console.log(n.name,"node")
                            let name=n.name;
                            const animationDef = animationDefinition[name];
                            //console.log(animationDef,"lkasnflnas")
                            n.data.push(new InteractionData({ hover: true, select: false }));
                            const times = typeof animationDef.times === "string"
                            ? JSON.parse(animationDef.times)
                            : animationDef.times;
                            const animationData: IAnimationData = new AnimationData(
                                n.name,
                                [
                                    {
                                        path: animationDef.type,
                                        // convert the rotation values to quaternions
                                        values: animationDef.values
                                            .map((v) => {
                                                const q = quat.setAxisAngle(quat.create(), v.axis, v.angle);
                                                return [q[0], q[1], q[2], q[3]];
                                            })
                                            .flat(),
                                        times: times as number[],
                                        pivot: animationDef.pivot,
                                        interpolation: 'linear',
                                        node: n
                                    }
                                ],
                                animationDef.start,
                                animationDef.duration
                            );
                            n.data.push(animationData);
                            //console.log(n,"newn")
                            n.updateVersion();
                            // animationData.startAnimation();
                            // animationData.repeat=true
                            Viewport.update();
                    })
                    }
                  }
        
              }
          }
    
          output.updateCallback(output.node)

SD Ticket (for DSGN) -164ed8e90d1813b4f68833b6d06d5c8af6821c9521a2a8f862741c5e63b2faf5235aa9c06131e09a0df9eb11c7808ab92777c6dd852035caee12f2c0e346545eb5621af8830382ba01e2780ab97a9ffbba561339aa7536d035b138f4ad1092d515dd1af9273087-5645583af8deaca8206f73e02faf2280

Cheers,

Amod

Hello @Amod_Katiyar,

as you correctly guessed, this is a timing issue!

What you can do though is to use the waitForViewportUpdate parameter in the customize call.
By setting this to true, the outputs should already be fully loaded by the time you get into the updateCallback.

Let me know if that works for you.

Cheers, Michael