### 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("  -b, --breakpoints                 Breakpoint list as source::line comma-separated pairs, no spaces (use %%20 instead).\n");
	OS::get_singleton()->print("  --profiling                       Enable profiling in the script debugger.\n");
	OS::get_singleton()->print("  --gpu-profile                     Show a GPU profile of the tasks that took the most time during frame rendering.\n");
	OS::get_singleton()->print("  --gpu-validation                  Enable graphics API validation layers for debugging.\n");
#if DEBUG_ENABLED
	OS::get_singleton()->print("  --gpu-abort                       Abort on graphics API usage errors (usually validation layer errors). May help see the problem if your system freezes.\n");
#endif
	OS::get_singleton()->print("  --remote-debug <uri>              Remote debug (<protocol>://<host/IP>[:<port>], e.g. tcp://127.0.0.1:6007).\n");
	OS::get_singleton()->print("  --single-threaded-scene           Scene tree runs in single-threaded mode. Sub-thread groups are disabled and run on the main thread.\n");
#if defined(DEBUG_ENABLED)
	OS::get_singleton()->print("  --debug-collisions                Show collision shapes when running the scene.\n");
	OS::get_singleton()->print("  --debug-paths                     Show path lines when running the scene.\n");
	OS::get_singleton()->print("  --debug-navigation                Show navigation polygons when running the scene.\n");
	OS::get_singleton()->print("  --debug-avoidance                 Show navigation avoidance debug visuals when running the scene.\n");
	OS::get_singleton()->print("  --debug-stringnames               Print all StringName allocations to stdout when the engine quits.\n");
#endif
	OS::get_singleton()->print("  --frame-delay <ms>                Simulate high CPU load (delay each frame by <ms> milliseconds).\n");
	OS::get_singleton()->print("  --time-scale <scale>              Force time scale (higher values are faster, 1.0 is normal speed).\n");
	OS::get_singleton()->print("  --disable-vsync                   Forces disabling of vertical synchronization, even if enabled in the project settings. Does not override driver-level V-Sync enforcement.\n");
	OS::get_singleton()->print("  --disable-render-loop             Disable render loop so rendering only occurs when called explicitly from script.\n");
	OS::get_singleton()->print("  --disable-crash-handler           Disable crash handler when supported by the platform code.\n");
	OS::get_singleton()->print("  --fixed-fps <fps>                 Force a fixed number of frames per second. This setting disables real-time synchronization.\n");
	OS::get_singleton()->print("  --delta-smoothing <enable>        Enable or disable frame delta smoothing ['enable', 'disable'].\n");
	OS::get_singleton()->print("  --print-fps                       Print the frames per second to the stdout.\n");
	OS::get_singleton()->print("\n");
	OS::get_singleton()->print("Standalone tools:\n");
	OS::get_singleton()->print("  -s, --script <script>             Run a script.\n");
	OS::get_singleton()->print("  --main-loop <main_loop_name>      Run a MainLoop specified by its global class name.\n");
	OS::get_singleton()->print("  --check-only                      Only parse for errors and quit (use with --script).\n");
#ifdef TOOLS_ENABLED