The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I have made a model in Blender and imported it to Godot 4 Beta 10 as a .glb file. If I doubleclick the .glb file it opens import-settings where I can choose the Node's root type, for example a StaticBody3D. Then I can load and instantiate the .glb file as a Scene and have a StaticBody3D in my game. Great.

But I have created a custom class that extends StaticBody3D and I would like to use that when I instantiate the node. I would like to choose my script from the import settings as I choose the root type but that option is not available.

I have found only one way to do that. The steps are:

  1. Select .glb, right mouser click -> New Inherited scene
  2. Click the movie-symbol on the right side of the root-node -> Open anyway
  3. Select the root-node of the new scene, add a new Node3d
  4. Click the Node3D with right mouse button -> Make scene root
  5. Right click previous root node that is not root anymore -> Save branch as scene...
  6. Assing the custom script to the new .tscn scene.

This is hilariously cumbersome and must be repeated every time when the model changes. Any ideas how to do that easier?

Godot version Godot 4 Beta 10
in Engine by (95 points)

1 Answer

0 votes
Best answer

The way You presented here is not only tedious, it is also blocking any option of reimporting assets.

What You are looking for is post_import tool scripting. Create new script :

tool
extends EditorScenePostImport


func post_import(scene):

And than You can manipulate the root ( scene ) any way You want, but You have to return it. For example :

func post_import(scene):
    scene.replace_by(yourcustombody)
            return yourcustombody

Or manually rechild mesh instances to new custom body and so on, You will figure it out :)

Now You just place this script in Import Settings in custom script slot and press reimport

by (8,188 points)
selected by

Thanks, using an import script fixes the problem.

I'm using C# and apparently C# import scripts are broken but I managed to write one in GDScript that creates a node from my class and assigns it to the imported scene:

@tool 

extends EditorScenePostImport

func _post_import(scene):
    print("importing small ship")

    var smallShipClassScript = load("res://src/SmallShip.cs")
    var smallShipNode = smallShipClassScript.new();
    scene.replace_by(smallShipNode);
    scene.free()
    return smallShipNode
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.