2017-11-24 08:16:27 +00:00
<?xml version="1.0" encoding="UTF-8" ?>
2023-07-05 20:07:03 +00:00
<class name= "EditorScenePostImport" inherits= "RefCounted" version= "4.2" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2017-11-24 08:16:27 +00:00
<brief_description >
2019-06-21 23:04:47 +00:00
Post-processes scenes after import.
2017-11-24 08:16:27 +00:00
</brief_description>
<description >
2019-06-21 23:04:47 +00:00
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.
2021-05-15 21:48:59 +00:00
The [method _post_import] callback receives the imported scene's root node and returns the modified version of the scene. Usage example:
2020-09-13 12:45:36 +00:00
[codeblocks]
[gdscript]
2022-09-21 20:49:03 +00:00
@tool # Needed so it runs in editor.
2018-09-21 13:34:11 +00:00
extends EditorScenePostImport
2023-01-31 17:21:09 +00:00
2020-09-13 12:45:36 +00:00
# This sample changes all node names.
# Called right after the scene is imported and gets the root node.
2021-05-15 21:48:59 +00:00
func _post_import(scene):
2019-06-21 23:04:47 +00:00
# Change all node names to "modified_[oldnodename]"
2018-09-21 13:34:11 +00:00
iterate(scene)
2019-06-21 23:04:47 +00:00
return scene # Remember to return the imported scene
2023-01-31 17:21:09 +00:00
2018-09-21 13:34:11 +00:00
func iterate(node):
if node != null:
2018-12-14 08:37:19 +00:00
node.name = "modified_" + node.name
2018-09-21 13:34:11 +00:00
for child in node.get_children():
iterate(child)
2020-09-13 12:45:36 +00:00
[/gdscript]
[csharp]
using Godot;
// This sample changes all node names.
// Called right after the scene is imported and gets the root node.
[Tool]
2022-12-07 10:37:28 +00:00
public partial class NodeRenamer : EditorScenePostImport
2020-09-13 12:45:36 +00:00
{
2023-01-31 17:21:09 +00:00
public override GodotObject _PostImport(Node scene)
2020-09-13 12:45:36 +00:00
{
// Change all node names to "modified_[oldnodename]"
2022-12-07 10:37:28 +00:00
Iterate(scene);
2020-09-13 12:45:36 +00:00
return scene; // Remember to return the imported scene
}
2023-01-31 17:21:09 +00:00
2020-09-13 12:45:36 +00:00
public void Iterate(Node node)
{
if (node != null)
{
2023-01-31 17:21:09 +00:00
node.Name = $"modified_{node.Name}";
2020-09-13 12:45:36 +00:00
foreach (Node child in node.GetChildren())
{
Iterate(child);
}
}
}
}
[/csharp]
[/codeblocks]
2018-09-21 13:34:11 +00:00
</description>
<tutorials >
2021-11-15 09:43:07 +00:00
<link title= "Importing 3D scenes: Custom script" > $DOCS_URL/tutorials/assets_pipeline/importing_scenes.html#custom-script</link>
2018-09-21 13:34:11 +00:00
</tutorials>
2017-11-24 08:16:27 +00:00
<methods >
2021-05-15 21:48:59 +00:00
<method name= "_post_import" qualifiers= "virtual" >
2021-07-30 13:28:05 +00:00
<return type= "Object" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "scene" type= "Node" />
2017-11-24 08:16:27 +00:00
<description >
2019-06-21 23:04:47 +00:00
Called after the scene was imported. This method must return the modified version of the scene.
2017-11-24 08:16:27 +00:00
</description>
</method>
2021-05-15 21:48:59 +00:00
<method name= "get_source_file" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "String" />
2021-05-15 21:48:59 +00:00
<description >
Returns the source file path which got imported (e.g. [code]res://scene.dae[/code]).
</description>
</method>
2017-11-24 08:16:27 +00:00
</methods>
</class>