Scripting 1.0 to scripting 2.0

Hi guys,

we have a big project (14 scenes, more than 100 components) that we wanna port from 1.0 to 2.0.

The approach we will try:

  1. export our project
  2. Port all our scripts to 2.0
  3. Modify the script object structure in all json of scenes
  4. Import project back.

Are we forgetting something? There is a certainly a scripting version to change somewhere plus other thing to do.

Is import a project create new ids for all assets? If yes, does it take care of changing all assets ids (even those in the assets attribute)?

Thanks for your time
David

Upgrading a project from scripts 1.0 to scripts 2.0 is a manual process. The time taken to perform the process will be related to the complexity of the project (e.g. the number of entities, entity attributes and assets).

I have not tried the method you suggest so I can’t vouch for whether it would work. So I’ll outline a couple of other options instead. Here’s the technique I use:

  1. Fork your project to back it up. This fork will also be a reference for retrieving attribute values that you’ve set (in a later step).
  2. In the original project, download all scripts (in a zip) from the project dashboard.
  3. Delete all scripts from the scripts folder in the Assets panel.
  4. Delete all script components from all entities in the Hierarchy panel. Here’s a handy script to run in the console to select all such entities:
var entities = editor.call('entities:list').filter(function(entity) {
    return entity.has('components.script');
});
if (entities.length) {
    editor.call('selector:set', 'entity', entities);
} else {
    editor.call('selector:clear');
}

.
5. Go to the Scripts Priority dialog and ensure you remove all scripts listed there.
6. Now you’re ready to upgrade your project to version 2.0. But only we can do that - you have to message us with the project id and we’ll flip the switch.
7. Drag your scripts back into the Assets panel. Now they’ll be true assets!
8. Upgrade each script to the new format. This format is documented here. This can be the most time consuming part! But it’s quite mechanical really. Update script attributes to the new format. Lose the constructor, moving whatever is necessary to the initialize function. If you have used onEnable/onDisable, switch to using events.
9. In your ‘backup’ fork, select all entities with script components again, using the script above.
10. Add a script component to all the corresponding entities in the upgraded project and assign the relevant scripts.
11. Go through all entities and set the attributes to the correct values based on what is set in the ‘backup’ project.
12. Go to the Settings panel and customize the script loading order as necessary.
13. Debug until you fix all the problems.

The other, slower alternative is to:

  1. Create a new project.
  2. Reupload all assets.
  3. Manually recreate the hierarchy.
  4. Reformat all the scripts.
  5. Manually set all script attributes to the correct values.
  6. Debug.

Using the first technique, I can normally convert even very complex projects in less than a day.

Thank you.

Unfortunately, our scenes have hundreds of entities and components with a lot of attributes. It will take a lot of days to do it manually and also add to this the “human error factor” when ajusting all attributes and component.

We have already ported our 150 components to 2.0 (We still need to change all onEnable/onDisable for a big part of them. We weren’t aware of that change :))

We will try to fork our 1.0 project and fork the new 2.0 project with all ours assets in it and “map” everything correctly from the json of the scenes itself by respecting the new object structure (for scripting).

One thing you need to know is that you cannot modify the files of a project export and then reimport it. A project export cannot be modified at all otherwise import will fail.

Can you explain why modifying the jsons of scenes by respecting the object structure and mapping everything correctly will failed? Is there a file hash check?

Indeed, there is a file hash check.