Arrays across scenes
-
Hello all,
I’m hoping there is a quick answer to this and that it is possible.
I want to store data in a number of arrays that can be accessed by a number of different scenes.
My plan was to put some main arrays in to a scene specifically for it and retrieve/modify data directly from those scenes. I’ve tried doing a number of things such as broadcast etc but I expect this may not be working because the scene with the arrays isn’t loaded.
Has anyone else done this? It seems like the best way to manage lots of different arrays needing accessed by lots of scens.
Anyway, thanks in advance for your help.
-
I think I may have answered my own question. By using the save to and load from file option. Only downside is that that I would need to load the scene first to save the array so it can be accessed later by scenes.
-
@Stuart_McKay Yep, what you’ve found is the only way to share information between scenes, save and load to file.
-
@Stuart_McKay @Aidan_Fire You can also use Global UI objects to share information between scenes.
For example, you could place a label in Global UI layer, and use that as the shareable array between scenes.
Here's a quick example I've made (if it doesn't open, long-press the link and tap Open Link):
Share Global Array Example.tapThis is just a basic example. You could also utilise Broadcast/Receive Message behaviours for more advanced functionality, e.g. auto-updating information when the array changes.
-
@Kamdroid Ah ha, good shout, I may experiment with this a bit more.
-
@Stuart_McKay As already suggested above, you can save and load data via the save to file and load from file behavior. You can also store attributes on a global object and switch scenes, as long as the global UI doesn't reset.
Another way you can do this is put the array in the global behaviors. Global behaviors are behaviors that are shared across all scenes - they can be accessed by clicking on the globe icon in the scene editor.
-
@Kamdroid Literally no idea why I haven’t tried that yet, and if I have tried it no idea why I’m not doing it.