How to transfer data between scenes?

There is a similar topic, no need to reply Click
Thank you
Hello, there is an object named “Player” in the “Scene-1” scene and I have a scrptim attached to that object.

I’m holding a “count” value. This value increases as a result of certain events. How do I send the final value of this value to the “text” object in another scene, “GameOver”?

Controller.attributes.add('count',{
   type: 'number',
    default: 1
});

   if(result.other.tags.has('dest')){
         this.count++;
         this.countText.element.text= this.count;
} 

Hi there Onur_Ozturk

The SceneRegistry has a method for loading a scene hierarchy that executes a callback when the new scene is loaded. I think you can put your data as a parameter in that callback.
See SceneRegistry | PlayCanvas API Reference

Another way of doing it is making that data a global variable so you can access it from anywhere. But I don’t think this would be a good idea for large amounts of data.
window.globalData = {all yor data inside}

Does it make sense to you?

Cheers

2 Likes

Hello, thank you for your reply. Your solution suggestion makes sense because I’m going to store a maximum of 3 digits, not a big data. Thanks again, I’ll try this.

1 Like

Hi Franciso,

Is is possible to change this global data during runtime?