godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.12k stars 21.19k forks source link

Cannot get class when setting root type import setting to class inherited from custom class #77076

Open rcorre opened 1 year ago

rcorre commented 1 year ago

Godot version

4.0.2.stable.arch_linux

System information

Linux

Issue description

If you have a chain of inherited classes, e.g. CharacterBody3D > Base > Child, you cannot set the Root Type of an imported scene to Child.

Steps to reproduce

  1. Create a script with class_name Base that extends CharacterBody3D
  2. Create a script with class_name Child that extends Base
  3. Add a .blend file to the project
  4. In the import settings for the blend file, set "Root Type" to Base
  5. Click "Reimport"
  6. See "Cannot find class Base"

Minimal reproduction project

example.zip

miwig commented 2 months ago

In 4.3.stable.arch_linux this also seems to be able to manifest as

Script inherits from native type ‘CharacterBody3D’, so it can’t be assigned to an object of type: ‘Node3D’

A workaround seems to be to set the Root Type in the import as CharacterBody3D and attach the Child script manually.

miwig commented 2 months ago

Also, annoyingly, if the initial hierarchy is CharacterBody3D > Child and Base is added later, the error seems to only appear after a reimport, meaning that a fresh clone of the project repository will show the error, while existing working copies remain unaffected.

Ninjaboi8175 commented 3 weeks ago

Confirmed this is still an issue on both latest stable (v4.3.stable.official [77dcf97d8]) and dev-snapshot (v4.4.dev3.official [f4af8201b]). Did a little digging and found that the error seems to come from:

resource_importer_scene.cpp

String root_type = p_options["nodes/root_type"]; if (!root_type.is_empty()) { root_type = root_type.split(" ")[0]; // Full root_type is "ClassName (filename.gd)" for a script global class. Ref Githubissues.

  • Githubissues is a development platform for aggregating issues.