# Scene event after create has completed

**URL:** <https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615>\
**Category:** Phaser 3\
**Created:** [August 30, 2019, 1:14am UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615 "2019-08-30T01:14:57Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![jorbascrumps](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jorbascrumps/32/1649_2.png) [@jorbascrumps](https://phaser.discourse.group/u/jorbascrumps)\
**Post date:** [August 30, 2019, 1:14am UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/1 "2019-08-30T01:14:57Z")

</div>

Hi guys,

I posed this question on Slack as well but thought I’d try my hand here, too.

I’d like to trigger an event after a potentially long running Scene initialization. Is there an event for when _after_ `Scene#create` has _finished?_ I know there’s [`Phaser.Scenes.Events.CREATE_EVENT`](https://photonstorm.github.io/phaser3-docs/Phaser.Scenes.Events.html#event:CREATE__anchor) for something similar, but I think that may be for when it’s _called_ and doesn’t account for execution time.

TIA

---

<div class="post-metadata">

**Author:** ![Jackolantern](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jackolantern/32/450_2.png) [@Jackolantern](https://phaser.discourse.group/u/Jackolantern)\
**Post date:** [August 30, 2019, 1:33am UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/2 "2019-08-30T01:33:52Z")

</div>

Are you needing it _right_ after create() finishes? Is it something you can do once in update(), because it runs after create().

Maybe knowing the context of the problem would help.

---

<div class="post-metadata">

**Author:** ![Jackolantern](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jackolantern/32/450_2.png) [@Jackolantern](https://phaser.discourse.group/u/Jackolantern)\
**Post date:** [August 30, 2019, 1:36am UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/3 "2019-08-30T01:36:37Z")

</div>

There is also READY and PREUPDATE. Maybe one of those could do what you are looking for.

---

<div class="post-metadata">

**Author:** ![jorbascrumps](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jorbascrumps/32/1649_2.png) [@jorbascrumps](https://phaser.discourse.group/u/jorbascrumps)\
**Post date:** [August 30, 2019, 2:04am UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/4 "2019-08-30T02:04:29Z")

</div>

@Jackolantern I want to fire an event, once, after `create` has completed finished. Ideally I’d like to avoid doing something to hack around it like running it in `update`.

I’m working on a scene transition and I don’t want the “in” transition to trigger until the scene has set itself up. In other words, I’d like to show a blank screen until the scene is ready to go and then animate in. The problem is that `create` may take some arbitrary amount of time (ie, perhaps spawning loads of enemies or generating a large map).

---

<div class="post-metadata">

**Author:** ![Jackolantern](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jackolantern/32/450_2.png) [@Jackolantern](https://phaser.discourse.group/u/Jackolantern)\
**Post date:** [August 30, 2019, 2:09am UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/5 "2019-08-30T02:09:34Z")

</div>

Hmmm…maybe the READY event would work. I do get not wanting to put it in update(), but if READY doesn’t work, maybe you could use PREUPDATE. I don’t know if that would keep firing with each update, but you could stop listening at the end of the event handler so it would effectively only run once. Maybe not extremely ideal, but it also doesn’t feel super hacky to me.

It would be nice if we had (lifecycleEvent)Complete events for each lifecycle stage, like initComplete, preloadComplete, createComplete, etc., but it doesn’t seem that anything exactly like that exists.

---

<div class="post-metadata">

**Author:** ![Jackolantern](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jackolantern/32/450_2.png) [@Jackolantern](https://phaser.discourse.group/u/Jackolantern)\
**Post date:** [August 30, 2019, 2:27am UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/6 "2019-08-30T02:27:12Z")

</div>

Ahhh, I think I’ve got it!

```
this.events.once('preupdate', function() {
    console.log('gameScene started!');
});

```

I actually didn’t know it supported once() until I went digging through the EventEmitter documentation. That is about the cleanest solution I can find, short of (blank)Complete events being added.

---

<div class="post-metadata">

**Author:** ![jorbascrumps](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jorbascrumps/32/1649_2.png) [@jorbascrumps](https://phaser.discourse.group/u/jorbascrumps)\
**Post date:** [August 30, 2019, 1:22pm UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/7 "2019-08-30T13:22:50Z")

</div>

Turns out that the `create` event _does_ work correctly. Through some discussion on Slack this morning, we found out that my issue is that events don’t wait for async operations (this never crossed my mind).

I’m sure your solution would work in most scenarios, but I’ll need to rethink my approach because I need to do some scene setup with some data fetched from an API.

Thank you for taking the time to help me with this, @Jackolantern! It is very much appreciated.

---

<div class="post-metadata">

**Author:** ![Jackolantern](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jackolantern/32/450_2.png) [@Jackolantern](https://phaser.discourse.group/u/Jackolantern)\
**Post date:** [August 30, 2019, 10:02pm UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/8 "2019-08-30T22:02:33Z")

</div>

Ahhhh, yes, it will not wait for an async operation to complete. Can you wrap the async operation in a promise and put the code that would be in your create event handler inside a function in a THEN clause? That way, even when create goes out of scope no matter when your async operation completes, your code can respond to it? Since you are setting up a transition, could you hold the screen black or whatever the mid-point of your transition is until your async operation completes? You could keep a flag that would cause update to not begin executing until that promise resolves and you set the flag to allow update to begin running. That would prevent your logic from beginning without the data from the async call. I don’t know of a way to actually keep create() from completing and beginning update() without using flags.

Anyway, best of luck on it! And no problem at all. I am learning stuff as well when I look into issues with parts of Phaser I haven’t worked with a ton yet.

---

<div class="post-metadata">

**Author:** ![Jackolantern](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jackolantern/32/450_2.png) [@Jackolantern](https://phaser.discourse.group/u/Jackolantern)\
**Post date:** [August 30, 2019, 10:23pm UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/9 "2019-08-30T22:23:01Z")

</div>

Oh wait…what kind of data are you loading asynchronously? Did you know Phaser has a JSON loader? You can actually point its preloader at a REST endpoint and get the response as JSON (just be sure your API is looking for a GET). The preload() method will not continue on until the resources are loaded so it will wait for the async call to complete. If you need to do some kind of setup before you can make the call, is it something you could do in a boot scene before your game scene gets loaded? And any parameters your API needs could be passed as a querystring through the JSON preloader.

---

<div class="post-metadata">

**Author:** ![jorbascrumps](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jorbascrumps/32/1649_2.png) [@jorbascrumps](https://phaser.discourse.group/u/jorbascrumps)\
**Post date:** [August 30, 2019, 11:20pm UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/10 "2019-08-30T23:20:13Z")

</div>

It’s funny you mention using the JSON file loader because I actually [wrote an article](https://dev.to/jorbascrumps/loading-server-generated-tilemaps-with-phaser-4mm7) about doing basically that. I hadn’t considered using it here.

I think what’s going on here is that I’ve over-engineered what I’m working on. I’m trying to create a reusable piece of code to handle all sorts of implementation details in whatever configuration. I think I’m just going to have to outline these limitations and admit that it might not work in every situation.

The more I’m thinking about it the more I’m convinced that this is the way to go.

---

<div class="post-metadata">

**Author:** ![Jackolantern](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jackolantern/32/450_2.png) [@Jackolantern](https://phaser.discourse.group/u/Jackolantern)\
**Post date:** [August 30, 2019, 11:25pm UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/11 "2019-08-30T23:25:49Z")

</div>

I have a problem with doing the same thing. My day job is making enterprise software in .NET, and those same kinds of patterns creep into my games even though they are probably the wrong abstraction. The complexity starts exploding and before I know it, I have 5 projects in my solution, 40 folders with piles of classes in them and I don’t even have the login system completed lol.

I recently ran a project that got out of control because I was way over-complicating it. I am just about to start over and try to simplify and streamline everything, and only expand things out as I actually need the feature or run into performance issues when testing.

Well, best of luck to you! It seems like you are on the right trail! 🙂

EDIT: That is a nice tutorial, by the way! I think I will read that 😃

---

<div class="post-metadata">

**Author:** ![jorbascrumps](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jorbascrumps/32/1649_2.png) [@jorbascrumps](https://phaser.discourse.group/u/jorbascrumps)\
**Post date:** [August 30, 2019, 11:54pm UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/12 "2019-08-30T23:54:37Z")

</div>

Sounds like you’re a typical developer! 😛 I think we all have issues with this. I’ve been working on the same project for over 5 years (depressing now that I think of it), just refactoring it over and over again. At this point I think I just do it to learn and try something new, with tiny hints at progress along the way.

Thank you for the compliment! I hope you enjoy reading it. I’m working on a new one at the moment. This thread is part of my research for it, actually.

---

<div class="post-metadata">

**Author:** ![Jackolantern](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jackolantern/32/450_2.png) [@Jackolantern](https://phaser.discourse.group/u/Jackolantern)\
**Post date:** [August 31, 2019, 12:08am UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/13 "2019-08-31T00:08:55Z")

</div>

Nice! I will definitely keep an eye out for it. Do all of your tutorials and articles go up on that site?

---

<div class="post-metadata">

**Author:** ![jorbascrumps](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jorbascrumps/32/1649_2.png) [@jorbascrumps](https://phaser.discourse.group/u/jorbascrumps)\
**Post date:** [August 31, 2019, 12:25am UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/14 "2019-08-31T00:25:35Z")

</div>

Yep! I’ve only got the one so far. I recently decided that if I can’t finish a game I can at least contribute back to the community this way. I’ve been working on a [plugin](https://github.com/jorbascrumps/phaser-plugin-list-view) or [two](https://github.com/jorbascrumps/phaser-plugin-water-body) as well.

---

<div class="post-metadata">

**Author:** ![Jackolantern](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jackolantern/32/450_2.png) [@Jackolantern](https://phaser.discourse.group/u/Jackolantern)\
**Post date:** [August 31, 2019, 12:38am UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/15 "2019-08-31T00:38:48Z")

</div>

Oh, those looks nice! I will bookmark them and keep them in my toolbox. Thanks! 😉

---

<div class="post-metadata">

**Author:** ![jorbascrumps](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jorbascrumps/32/1649_2.png) [@jorbascrumps](https://phaser.discourse.group/u/jorbascrumps)\
**Post date:** [August 31, 2019, 1:02am UTC](https://phaser.discourse.group/t/scene-event-after-create-has-completed/3615/16 "2019-08-31T01:02:48Z")

</div>

Great! Would love any feedback you have if you ever find a use for them.
