# Any tips for making a cross-scene manager / singleton?

**URL:** <https://phaser.discourse.group/t/any-tips-for-making-a-cross-scene-manager-singleton/4578>\
**Category:** Phaser 3\
**Created:** [December 12, 2019, 8:48pm UTC](https://phaser.discourse.group/t/any-tips-for-making-a-cross-scene-manager-singleton/4578 "2019-12-12T20:48:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmr](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/cmr/32/2446_2.png) [@cmr](https://phaser.discourse.group/u/cmr)\
**Post date:** [December 12, 2019, 8:48pm UTC](https://phaser.discourse.group/t/any-tips-for-making-a-cross-scene-manager-singleton/4578/1 "2019-12-12T20:48:55Z")

</div>

New to Phaser 3 in general, and coming from briefly using Unity. In Unity, a common pattern is to use a Singleton Game Manager to manage state, and can use “Don’t Destroy on Load” to keep it active among scenes. Any tips to recreate a similar pattern in Phaser?

I have an inventory that needs to be updated globally, but I switch scenes constantly to explore an environment, as each section of the environment is its own scene.

I’ve briefly looked into the [data section](https://rexrainbow.github.io/phaser3-rex-notes/docs/site/datamanager/), it seems I can use this / attach my own objects to this (?). Anyone encounter a similar problem / have a good solution? Thanks.

---

<div class="post-metadata">

**Author:** ![snowbillr](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/snowbillr/32/332_2.png) [@snowbillr](https://phaser.discourse.group/u/snowbillr)\
**Post date:** [December 12, 2019, 9:08pm UTC](https://phaser.discourse.group/t/any-tips-for-making-a-cross-scene-manager-singleton/4578/2 "2019-12-12T21:08:46Z")

</div>

I just did something like this! I created a `PersistencePlugin` that’s a global plugin for the game.

You can take a look at it here: [https://github.com/snowbillr/archer-adventure/blob/master/src/plugins/persistence-plugin.ts](https://github.com/snowbillr/archer-adventure/blob/master/src/plugins/persistence-plugin.ts)

and see how it’s loaded into the game here: [https://github.com/snowbillr/archer-adventure/blob/master/src/index.ts#L24](https://github.com/snowbillr/archer-adventure/blob/master/src/index.ts#L24)

and see how I use it here [https://github.com/snowbillr/archer-adventure/blob/master/src/scenes/hud-scene.ts#L21](https://github.com/snowbillr/archer-adventure/blob/master/src/scenes/hud-scene.ts#L21) and here [https://github.com/snowbillr/archer-adventure/blob/master/src/components/adventurer-component.ts#L35](https://github.com/snowbillr/archer-adventure/blob/master/src/components/adventurer-component.ts#L35)

At its core its just a key/value store that’s stored on the game level rather than the scene level.

---

<div class="post-metadata">

**Author:** ![cmr](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/cmr/32/2446_2.png) [@cmr](https://phaser.discourse.group/u/cmr)\
**Post date:** [December 12, 2019, 9:21pm UTC](https://phaser.discourse.group/t/any-tips-for-making-a-cross-scene-manager-singleton/4578/3 "2019-12-12T21:21:31Z")

</div>

Woah! This looks like exactly what I need.

New to Typescript, and the concept of “Plugins” so I’m probably gonna study your code / the syntax for a bit haha. I’ll let you know if I have any questions!!

---

<div class="post-metadata">

**Author:** ![snowbillr](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/snowbillr/32/332_2.png) [@snowbillr](https://phaser.discourse.group/u/snowbillr)\
**Post date:** [December 12, 2019, 9:24pm UTC](https://phaser.discourse.group/t/any-tips-for-making-a-cross-scene-manager-singleton/4578/4 "2019-12-12T21:24:46Z")

</div>

Sounds good, happy to help!

TL;DR on plugins: they are either at the Scene level or the Game level. Scene plugins have an instance given to every scene, Game plugins have a single instance given to the game.
