### 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()->add_frame_delay(DisplayServer::get_singleton()->window_can_draw());
#ifdef TOOLS_ENABLED
	if (auto_build_solutions) {
		auto_build_solutions = false;
		/
		if (!editor) {
			OS::get_singleton()->set_exit_code(EXIT_FAILURE);
			ERR_FAIL_V_MSG(true,
					"Command line option --build-solutions was passed, but no project is being edited. Aborting.");
		}
		if (!EditorNode::get_singleton()->call_build()) {
			OS::get_singleton()->set_exit_code(EXIT_FAILURE);
			ERR_FAIL_V_MSG(true,
					"Command line option --build-solutions was passed, but the build callback failed. Aborting.");
		}
	}
#endif
	return exit;
}
void Main::force_redraw() {
	force_redraw_requested = true;
}
/* Engine deinitialization
 *
 * Responsible for freeing all the memory allocated by previous setup steps,
 * so that the engine closes cleanly without leaking memory or crashing.
 * The order matters as some of those steps are linked with each other.
 */
void Main::cleanup(bool p_force) {