EditorScenePostImport.xml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="EditorScenePostImport" inherits="RefCounted" version="4.0">
  3. <brief_description>
  4. Post-processes scenes after import.
  5. </brief_description>
  6. <description>
  7. Imported scenes can be automatically modified right after import by setting their [b]Custom Script[/b] Import property to a [code]tool[/code] script that inherits from this class.
  8. The [method _post_import] callback receives the imported scene's root node and returns the modified version of the scene. Usage example:
  9. [codeblocks]
  10. [gdscript]
  11. tool # Needed so it runs in editor.
  12. extends EditorScenePostImport
  13. # This sample changes all node names.
  14. # Called right after the scene is imported and gets the root node.
  15. func _post_import(scene):
  16. # Change all node names to "modified_[oldnodename]"
  17. iterate(scene)
  18. return scene # Remember to return the imported scene
  19. func iterate(node):
  20. if node != null:
  21. node.name = "modified_" + node.name
  22. for child in node.get_children():
  23. iterate(child)
  24. [/gdscript]
  25. [csharp]
  26. using Godot;
  27. // This sample changes all node names.
  28. // Called right after the scene is imported and gets the root node.
  29. [Tool]
  30. public class NodeRenamer : EditorScenePostImport
  31. {
  32. public override Object PostImport(Object scene)
  33. {
  34. // Change all node names to "modified_[oldnodename]"
  35. Iterate(scene as Node);
  36. return scene; // Remember to return the imported scene
  37. }
  38. public void Iterate(Node node)
  39. {
  40. if (node != null)
  41. {
  42. node.Name = "modified_" + node.Name;
  43. foreach (Node child in node.GetChildren())
  44. {
  45. Iterate(child);
  46. }
  47. }
  48. }
  49. }
  50. [/csharp]
  51. [/codeblocks]
  52. </description>
  53. <tutorials>
  54. <link title="Importing 3D scenes: Custom script">https://docs.godotengine.org/en/latest/tutorials/assets_pipeline/importing_scenes.html#custom-script</link>
  55. </tutorials>
  56. <methods>
  57. <method name="_post_import" qualifiers="virtual">
  58. <return type="Object" />
  59. <argument index="0" name="scene" type="Node" />
  60. <description>
  61. Called after the scene was imported. This method must return the modified version of the scene.
  62. </description>
  63. </method>
  64. <method name="get_source_file" qualifiers="const">
  65. <return type="String" />
  66. <description>
  67. Returns the source file path which got imported (e.g. [code]res://scene.dae[/code]).
  68. </description>
  69. </method>
  70. </methods>
  71. </class>