### Godot version

4.0 beta 10, also 3.5.1

### System information

Windows 11

### Issue description

Creating a Mainloop inherited from SceneTree makes sense when you want to add a few features to SceneTree instead of starting from scratch. Unfortunately, this doesn't work as well, as if its type is erased.

But inheriting from Mainloop directly (in the example) can work properly.


### Steps to reproduce

1. Create a mainloop extends SceneTree. In this case, I call it `MyGDScriptMainLoop`.

```gdscript
class_name MyGDScriptMainLoop extends SceneTree

func say_hello():
    print("hello")
```

2. Go to project settings, set `application/run/main_loop_type` to `MyGDScriptMainLoop`.
3. Create a test scene and try to call `Engine.get_main_loop().say_hello()`.

```gdscript
extends Node2D


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
    Engine.get_main_loop().say_hello()
    pass # Replace with function body.
```

Then you will see:

![image](https://user-images.githubusercontent.com/93276898/210129049-0250a15f-2f87-49a1-b066-16ef5e695302.png)

And also I found that `Engine.get_main_loop() is MyGDScriptMainLoop` is `false`.

Using GDExtension to do this also failed. But since I'm using godot-rust, I'm not sure if this problem exists with godot-cpp.

### Minimal reproduction project

[bug.zip](https://github.com/godotengine/godot/files/10327002/bug.zip)

static bool debug_navigation = false;
static bool debug_avoidance = false;
#endif
static int frame_delay = 0;
static bool disable_render_loop = false;
static int fixed_fps = -1;
static MovieWriter *movie_writer = nullptr;
static bool disable_vsync = false;
static bool print_fps = false;
#ifdef TOOLS_ENABLED
static bool dump_gdextension_interface = false;
static bool dump_extension_api = false;
static bool validate_extension_api = false;
static String validate_extension_api_file;
#endif
bool profile_gpu = false;
static const String NULL_DISPLAY_DRIVER("headless");
static const String NULL_AUDIO_DRIVER("Dummy");
bool Main::is_cmdline_tool() {
	return cmdline_tool;
}
#ifdef TOOLS_ENABLED
const Vector<String> &Main::get_forwardable_cli_arguments(Main::CLIScope p_scope) {
	return forwardable_cli_arguments[p_scope];
}
#endif
static String unescape_cmdline(const String &p_str) {
	return p_str.replace("%20", " ");
}
static String get_full_version_string() {