godot: Mono: AutoLoad inheriting Node still gives error: Script does not inherit a Node


Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.


Godot version: 3.2 stable mono OS/device including version: Debian 10 Issue description:

E 0:00:00.662   start: Script does not inherit a Node: res://AutoLoad/GodotUtilities.cs
  <C++ Error>   Condition "!valid_type" is true. Continuing.
  <C++ Source>  main/main.cpp:1693 @ start()
E 0:00:00.666   start: Script does not inherit a Node: res://AutoLoad/Pool.cs
  <C++ Error>   Condition "!valid_type" is true. Continuing.
  <C++ Source>  main/main.cpp:1693 @ start()

Steps to reproduce:

namespace GodotUtilities
{
    public class Log : Node
    {
public class Pool<T> : Node where T : new()
{

Minimal reproduction project: NA

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 9
  • Comments: 49 (7 by maintainers)

Most upvoted comments

Script does not inherit from Node error is still present on v4.1.stable.mono.official [970459615]

Steps to reproduce:

  1. Create empty C# Godot project
  2. Create C# script Test.cs with this code
using Godot;

public partial class Test : Node
{
}
  1. Open “Project” -> “Project Settings” -> “Autoload”
  2. Select Path to Test.cs and click Add button
  3. This error is printed to the console:
ERROR: Script does not inherit from Node: res://Test.cs.
   at: (editor/editor_autoload_settings.cpp:423)
ERROR: Condition "!info->node" is true. Continuing.
   at: update_autoload (editor/editor_autoload_settings.cpp:551)

More errors: Closing “Project Settings” window and opening it again will print this error:

ERROR: Condition "!named_globals.has(p_name)" is true.
   at: remove_named_global_constant (modules/gdscript/gdscript.cpp:2047)
ERROR: Script does not inherit from Node: res://Test.cs.
   at: (editor/editor_autoload_settings.cpp:423)
ERROR: Condition "!info->node" is true. Continuing.
   at: update_autoload (editor/editor_autoload_settings.cpp:551)

And more errors: Clicking trash bin icon to remove Test.cs autoload will print this error:

ERROR: Condition "!named_globals.has(p_name)" is true.
   at: remove_named_global_constant (modules/gdscript/gdscript.cpp:2047)

There seems to be some confusion in this issue with unrelated reports, with some being bugs, some being misunderstandings.

This bug report is about C# scripts that inherit Node and are being used as an AutoLoad, and apparently the engine still complains that they don’t inherit Node. That’s a bug that needs to be fixed (if it’s still reproducible).

For GDScript users who write scripts that do not inherit Node (e.g. inherit Reference or Object), and get the error that the script does not inherit Node… well the error tells you the problem. Your AutoLoad needs to inherit Node, as it’s added as a Node to the scene tree.

Godot version: Godot_v3.2.3-stable_win64.exe

OS/device including version: Win 10 Pro

Issue Description: Autoload of gd-script raises error when not inheriting Node (or subclass of Node)

E 0:00:00.741   start: Script does not inherit a Node: res://new_script.gd
  <C++ Error>   Condition "!valid_type" is true. Continuing.
  <C++ Source>  main/main.cpp:1766 @ start()

Steps to reproduce:

  1. Create a new project
  2. Start with Node2D and save scene
  3. Add a gd source file that extends Object
  4. Add this script to Autoload
  5. Run (and set the saved scene as main scene)

Minimal project example: godot_test_issue36787.zip

I’ve run into this problem before. The error occurs when the Godot file name (e.g. my_class.cs) and the C# class name (e.g. MyClass) do not match. This is a catch-22 since the Godot standard for file naming is all lower case while C# class names are CamelCase. The solution is to assure the .cs file name exactly matches the C# class name.

I had this happen when my C# class name did not match the *.cs file name. Renaming the class fixed the error.

Edit: This issue showed up when exporting on Win10, but not when running in the editor. Making tscn files and changing the autload config solved it for the export. I also had capitalization mismatches in the paths of resources between loading things in the code, and referencing scenes in tscn files that needed to be resolved

I am new to Godot.

I am able to reproduce the issue on v4.0 .Net by just opening a community sample project “Godot .NET thirdperson controller”

Generating a new sln from the Tools menu fixed the issue for me, on that sample project 😕

Don’t know if this will help. I just ran into this error on a newly started project. The problem was caused by the C# Class name not matching the script file name.

For example, I created a new C# script inherited from Node and named the script file sentinel_file.cs. The C# generated code named the class SentinelFile (which is exactly what I wanted). However, the “does not inherit a Node” error resulted.

Changing the class name in the C# script to “sentinel_file” resolved the problem.

This also happened to me in 3.4 stable, I restarted the editor and it no longer shows me the error.

As the top of the issue states, no need to confirm this further, especially as people have just recently done the same

I am new to Godot.

I am able to reproduce the issue on v4.0 .Net by just opening a community sample project “Godot .NET thirdperson controller”

@Maclay74 Which Godot version are you using? Please always specify this information when reporting issues as still being reproducible 🙂

Note that this issue is likely fixed in 4.0.alpha16, as Mono was replaced by .NET 6 there.

Hey, sorry, I’m using 3.5.

I found that it happens only when adding autoload script before build. According to the implementation, I assume that at the moment of this check

Ref<Script> s = res;
StringName ibt = s->get_instance_base_type();
bool valid_type = ClassDB::is_parent_class(ibt, "Node");
ERR_FAIL_COND_V_MSG(!valid_type, nullptr, "Script does not inherit from Node: " + p_path + ".");

App doesn’t have this class in hashmap for some reason, so it fails.

HashMap<StringName, ClassDB::ClassInfo> ClassDB::classes;

bool ClassDB::_is_parent_class(const StringName &p_class, const StringName &p_inherits) {
	if (!classes.has(p_class)) {
		return false;
	}

	StringName inherits = p_class;
	while (inherits.operator String().length()) {
		if (inherits == p_inherits) {
			return true;
		}
		inherits = _get_parent_class(inherits);
	}

	return false;
}

4.0 alpha is cool, but not ready for C# yet

.NET 6 support should be included in 4.0 beta 1. The initial support has been merged, but more work is required to make official builds easily. For now, it’s possible to compile it yourself from source, see modules/mono/README.md for instructions.

In my case, all of my autoloads classes match the filenames. The error still happens. Also tried to make them partials, that didn’t work either.

(Linux user) Switching Build Tool to DotNet CLI solved my issue.

I had this error before because I renamed my project. I made this error go away by making sure the root project folder was the same name as the .csproj / .sln filenames. And I made sure to rename the project name in .sln and in project.godot files.

Godot was complaining that all the scripts in my autoload were not inheirted by nodes when they were. And when I removed all autoloads Godot started complaining about the same errors in every non-autoload script.

Can confirm this issue on Ubuntu 20.10 / Godot 3.2.3 and 3.2.2. Is there a workaround? This seems to make C# / Mono completely unusable.

Got this error after updating to 3.2.3. Godot version: 3.2.3 stable mono OS/device including version: Ubuntu 20.04.2 LTS Mono version: Mono JIT compiler version 6.8.0.105 Issue description: E 0:00:02.252 start: Script does not inherit a Node: res://script/Global.cs <C++ Error> Condition “!valid_type” is true. Continuing. <C++ Source> main/main.cpp:1766 @ start()