Godot: Post-import script is still broken

Created on 11 May 2020  路  5Comments  路  Source: godotengine/godot

Godot version: 3.2.1

OS/device including version: Windows 64 Pro

Issue description:

  • When trying to attach ANY post-import script to Custom Script property of Import, the following error is encountered:
    Error running post-import script:.....
  • While the code inside post-import() function seems to run just fine, the resulting file is NOT saved, so the import process fails

Steps to reproduce:
1) Create post-import script as per: https://godot-es-docs.readthedocs.io/en/latest/getting_started/workflow/assets/importing_scenes.html#import-options (Custom Script)
2) Attach to Custom Script property of Import of any file that can be imported, making sure it is set as Preset
3) Import / Re-import and witness the errors
4) Any import specific functions will fail (for example, if you set ESCN storage to Instanced Sub-Scenes, the import process will be unable to save SCN files)

Capture

archived

All 5 comments

As per the documentation, you are expected to return the modified scene from the post_import function. (Emphasis mine)

tool # needed so it runs in the editor
extends EditorScenePostImport

func post_import(scene):
  # do your stuff here
  return scene # **remember to return the imported scene**

The post_import function takes the imported scene as argument (the parameter is actually the root node of the scene). The scene that will finally be used must be returned. It can be a different one.

The error is, in fact, shown when the script returns something which is not a Node.
https://github.com/godotengine/godot/blob/32133a11b56761df99579ad96ee29a47d2aed6b4/editor/import/resource_importer_scene.cpp#L1583-L1585

@bojidar-bg
Shit, apologies, can not believe I made such stupid mistake.
Everything is working perfectly now and I can start making my script.
Thank you!

Not a bug, my own mistake

No worries, everyone runs into something once in a while. :) Glad you figured it out!

We should probably tweak the error message to make this more obvious. I can foresee a lot of people accidentally forgetting to return the modified scene :slightly_smiling_face:

Was this page helpful?
0 / 5 - 0 ratings