### 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)

}
			OS::get_singleton()->print("'%s'", rd[j].utf8().get_data());
		}
		OS::get_singleton()->print(")");
	}
	OS::get_singleton()->print("].\n");
	OS::get_singleton()->print("  --rendering-method <renderer>     Renderer name. Requires driver support.\n");
	OS::get_singleton()->print("  --rendering-driver <driver>       Rendering driver (depends on display driver).\n");
	OS::get_singleton()->print("  --gpu-index <device_index>        Use a specific GPU (run with --verbose to get available device list).\n");
	OS::get_singleton()->print("  --text-driver <driver>            Text driver (Fonts, BiDi, shaping).\n");
	OS::get_singleton()->print("  --tablet-driver <driver>          Pen tablet input driver.\n");
	OS::get_singleton()->print("  --headless                        Enable headless mode (--display-driver headless --audio-driver Dummy). Useful for servers and with --script.\n");
	OS::get_singleton()->print("  --write-movie <file>              Writes a video to the specified path (usually with .avi or .png extension).\n");
	OS::get_singleton()->print("                                    --fixed-fps is forced when enabled, but it can be used to change movie FPS.\n");
	OS::get_singleton()->print("                                    --disable-vsync can speed up movie writing but makes interaction more difficult.\n");
	OS::get_singleton()->print("                                    --quit-after can be used to specify the number of frames to write.\n");
	OS::get_singleton()->print("\n");
	OS::get_singleton()->print("Display options:\n");
	OS::get_singleton()->print("  -f, --fullscreen                  Request fullscreen mode.\n");
	OS::get_singleton()->print("  -m, --maximized                   Request a maximized window.\n");
	OS::get_singleton()->print("  -w, --windowed                    Request windowed mode.\n");
	OS::get_singleton()->print("  -t, --always-on-top               Request an always-on-top window.\n");
	OS::get_singleton()->print("  --resolution <W>x<H>              Request window resolution.\n");
	OS::get_singleton()->print("  --position <X>,<Y>                Request window position (if set, screen argument is ignored).\n");
	OS::get_singleton()->print("  --screen <N>                      Request window screen.\n");
	OS::get_singleton()->print("  --single-window                   Use a single window (no separate subwindows).\n");
	OS::get_singleton()->print("  --xr-mode <mode>                  Select XR (Extended Reality) mode ['default', 'off', 'on'].\n");
	OS::get_singleton()->print("\n");
	OS::get_singleton()->print("Debug options:\n");
	OS::get_singleton()->print("  -d, --debug                       Debug (local stdout debugger).\n");