How to extend NetworkedMultiplayerPeer in GDScript

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sulai

I’m using Godot 3.2.1 stable. In this section of the documentation, it says:

Godot uses a mid-level object NetworkedMultiplayerPeer. This object is not meant to be created directly, but is designed so that several implementations can provide it.

Since I need to implement a custom client (based on web socket), but want to use the higher-level networking like get_tree().set_network_peer(my_custom_client) and rpc() later on, I went ahead and tried to extend NetworkedMultiplayerPeer. This is the minimal example I came up with:

1 extends Node
3 class MyPeer extends NetworkedMultiplayerPeer:
4     func _init():
5 	    	pass
7 var peer =

However, turns out the super class is a virtual class, and I can’t create a new instance with The Error log says:

E 0:00:00.772   instance: Condition "!ti->creation_func" is true. Returned: __null
  <C++ Source>  core/class_db.cpp:540 @ instance()
  <Stack Trace> @ _init()
E 0:00:00.772   _new: Can't inherit from a virtual class.
  <C++ Error>   Condition "!owner" is true. Returned: Variant()
  <C++ Source>  modules/gdscript/gdscript.cpp:158 @ _new()
  <Stack Trace> @ _init()

Is there a simple trick I just don’t know about? Or is it entirely impossible to provide an implementation of NetworkedMultiplayerPeer in GDScript?

:bust_in_silhouette: Reply From: sulai

For answers to this question, see the github discussion.