Up to date

This page is up to date for Godot 4.0. If you still find outdated information, please open an issue.

EditorScenePostImport

Inherits: RefCounted < Object

Post-processes scenes after import.

Description

Imported scenes can be automatically modified right after import by setting their Custom Script Import property to a tool script that inherits from this class.

The _post_import callback receives the imported scene’s root node and returns the modified version of the scene. Usage example:

GDScriptC#

  1. @tool # Needed so it runs in editor.
  2. extends EditorScenePostImport
  3. # This sample changes all node names.
  4. # Called right after the scene is imported and gets the root node.
  5. func _post_import(scene):
  6. # Change all node names to "modified_[oldnodename]"
  7. iterate(scene)
  8. return scene # Remember to return the imported scene
  9. func iterate(node):
  10. if node != null:
  11. node.name = "modified_" + node.name
  12. for child in node.get_children():
  13. iterate(child)
  1. using Godot;
  2. // This sample changes all node names.
  3. // Called right after the scene is imported and gets the root node.
  4. [Tool]
  5. public partial class NodeRenamer : EditorScenePostImport
  6. {
  7. public override GodotObject _PostImport(Node scene)
  8. {
  9. // Change all node names to "modified_[oldnodename]"
  10. Iterate(scene);
  11. return scene; // Remember to return the imported scene
  12. }
  13. public void Iterate(Node node)
  14. {
  15. if (node != null)
  16. {
  17. node.Name = $"modified_{node.Name}";
  18. foreach (Node child in node.GetChildren())
  19. {
  20. Iterate(child);
  21. }
  22. }
  23. }
  24. }

Tutorials

Methods

Object

_post_import ( Node scene ) virtual

String

get_source_file ( ) const


Method Descriptions

Object _post_import ( Node scene ) virtual

Called after the scene was imported. This method must return the modified version of the scene.


String get_source_file ( ) const

Returns the source file path which got imported (e.g. res://scene.dae).