Cocos Creator Extension - _Scene singleton documentation

Cocos Creator Extension - _Scene singleton documentation



I’m building an Editor Extension for Cocos Creator where I need to parse a JSON file to create a Scene with objects based on the JSON (I have the parsers to do that) and then save the scene into a new file. I have read the documentation about Asset Management, where it recommend to use the _Scene singleton to Save and Load scenes but I can’t find the documentation of that singleton to check all the methods that it provide.

Basically what I need to do on my Editor Extension is Create Scene -> Parse my JSON and create the Nodes into the scene -> Save the scene into a .fire file.

After checking (and printing) the _Scene singleton, it seems that it has a method to create a new scene (“newScene”) but since I don’t have any kind of documentation (and I can’t see the source code of the singleton since is inside the asar package of CC) I don’t know how to use it. Also it seems that _Scene doesn’t have anymore the save() method, as I read on Doc.

Kind regards!


Don’t know if this can help, but you can see the source code of the engine in cocos repo.


thanks for your answer @amcgamer, unfortunately what I need is the Editor source code (I can understand why is not open) but all the potential to create extension would be easier if I could check what some thing are being done in the Editor (like create a new Scene and save it).



I’m still looking for a way to Save a Scene from code. the _Scene singleton doesn’t have what I need so if someone have done this before, I would appreciate to share it.



Creating Extension for CocosCreator is extremly hard atm. At least if you need to create some advanced tools.
The Documentation is bad and there is almost no support. There is no way to really extend the Editor.

What I found out so far (maybe not the best way) is…
You need to create a *.fire data-file (text file). (Iterate through all Scene Objects and write the data in this fire file). Maybe there is already a “create Fire File” function in the Editor API… but I don’t know it.
then Save this file (scene) with Editor.remote.assetdb.create(url, data);

That was the way I created my Animations dynamicly. (Writing Animation-Data is easy)


Hi @MuratAlbayrak ! Thanks for your answer.

Indeed that is a way to solve my problem, thanks! I thought about create the .fire file myself, the thing is I need to serialize the objects and for some reason the _serialize methods of the nodes are not working on my side (I need to take another look on that). With that serialize data I can write into the .fire file.

Will try that and notify on this post.



At the end I was able to fix my issue.

I found out that if you open the developer tools from the Editor (Developer->Developer Tools), you can go to the Sources tab and there you can see the unpacked uglify code of the Editor. After a deep search I found the .js who serialize and save an scene, this is how you can do it:

   let sceneAsset = new cc.SceneAsset();
   sceneAsset.scene = cc.director.getScene();
   //Here is the serialized data of the Scene in json format
   const sceneSerialized = Editor.serialize(sceneAsset); 

What the editor does is send the serialized data into a event to the main panel:
Editor.Ipc.sendToMain('scene:save-scene',path,serializedData, callback, -1);
This will open the ‘Save as’ panel of the editor to save an Scene.

On my case I just created a .fire file and save it:

  const newScenePath = 'db://assets/scenes/'+opt.sceneName+'.fire';
  Editor.assetdb.create(newScenePath, sceneSerialized, (err,result) =>{
         //Do something