There is unexpected behavior in my project. I am new to PlayCanvas and the problem certainly can be a fault in my code. The full code is included below.
- How can I change my sourcecode to meet my expected behavior?
- Does this demonstrate a PlayCanvas bug? If yes, when will it be fixed?
I created a demo project to test reloading the current scene. I attempt to use the recommendations I see on the forum.
Expected Behavior: During ONE session, it works the first time and EVERY time after the first.
Actual Behavior: During ONE session, it works the first time. Then breaks the 2nd time sometimes. It breaks the 3rd time always.
Log showing a) expected, b) expected, c) not expected
Here is my fixed fork: https://playcanvas.com/editor/scene/919880
When listening for events on object whose lifetime is not the same as the listener’s, it has to be removed at some point (in this case, the listener’s entity destroy event).
As it wasn’t removed, it was calling the callback twice the second time round.
Excellent. That workaround performs well.
It is unmanageable to handle a complete game this way.
As a core API request, I recommend a few mutually exclusive features
- API allows to load new scene non-addititively where nothing in runtime persists except the new scene (Unity calls this “Single” https://docs.unity3d.com/ScriptReference/SceneManagement.LoadSceneMode.Single.html)
- API treats destroy as a first class citizen of script (e.g. like “initialize” and “update”) and does not require manual listening.
- API allows for a version of observing events [e.g. "blah.on(“blah”, this.handle, this)] which will release the event subscription from blah if ‘this’ is destroyed.
- API allows for app.Restart() or similar which mimicks the first-run of the application which is somehow faster for developers than refreshing the page (takes about 5 seconds for me)
Great info per 1/2/3. Per #4…I don’t know how to answer the question. Here is a video of my (relatively small?) project as I refresh the browser.
Interesting. As you are using physics, that delay could be due to the Ammo physics library being parsed and started (it is a pretty hefty file and using WASM)
Edit: Doesn’t seem like it using my own project. I would look into the Chrome Devtools to see what could be causing it to take so long after a standard refresh. This a recent example project with Physics
Yes, this is a physics project using Ammo. In the video I shared, its about 5 seconds from clicking refresh to script’s initialize(). That was the latest firefox. I just tried in the latest chrome. Its about 4 seconds.
I’m very jealous of your < 1 second refresh
I’m new to JS & browser development. What can I disable in Chrome reduce the refresh time?
Is the project public? It be interesting to see if I can repro it on my local laptop. That will help isolate if it’s an engine issue vs maybe something to do with the local setup.
Edit: I do recommend looking at using the browser devtools as they are pretty awesome: https://developers.google.com/web/tools/chrome-devtools
They are able to give full breakdowns of CPU time, load time etc as well as the usual code debugging (breakpoints etc).