[ENGINE ONLY] Add scene

Hi, is it possible to add a scene JSON from an object, not via url.
I have already loaded a scene with axios and want to add the scene now
to the app

Hi @iso74,

There isn’t a public method in the API for that, but it’s definitely possible, I am doing this in a couple of projects of my own.

You will have to write your own scene loading methods that mirrors the engine one, without the json loading calls:

2 Likes

Uff sounds complicated, do you have a hint on how to get started on this?

Yes this is quite advanced, you will have to create a new handler of your own. That accepts a JS object instead of a string (url) to load the scene. I don’t have any code handy sorry.

You could make a feature request in the engine repo about it.

@Leonidas is it at least possible to listen to this event inside the loadScene() function?

entity.script.on(‘create’, function (name, scriptInstance) {
// new script instance added to component
});

Yes, sure, if the script asset is loaded and available to the engine, then that event will fire:

https://developer.playcanvas.com/en/api/pc.ScriptComponent.html#event:create

You might be able to turn your JSON object to a string and into a blob to get around this? Not a great solution though.

Out of interest, how does it become a JSON Object? Did it existing in a string form at some point.