Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make networking extendable from GDScript (NetworkedMultiplayerPeer) #38294

Closed
mhilbrunner opened this issue Apr 28, 2020 · 5 comments
Closed

Comments

@mhilbrunner
Copy link
Member

mhilbrunner commented Apr 28, 2020

NetworkedMultiplayerPeer is currently virtual and thus it's impossible to add new implementations or extension via GDScript.

This was brought to our attention in this issue, there's some discussion over there.

After a brief talk with Faless, while GDScript may not be the best tool for such extensions, but easy and fast for the user.

We should investigate the complexity of making NetworkedMultiplayerPeer extendable from GDScript :)

@Calinou
Copy link
Member

Calinou commented Apr 28, 2020

This issue is probably a better fit for the Godot proposals repository. Could you edit it to match the template? We can then move it there.

@mrimvo
Copy link

mrimvo commented Apr 28, 2020

I think we should generalize the focus of this ticket a bit more, because not only virtual classes like NetworkedMultiplayerPeer can't be extended in GDScript, but also ordinary classes like WebSocketClient. Minimalistic example for this:

extends Node

class MyPeer extends WebSocketClient:
        # this is not overriding as one might expect
	func get_available_packet_count() -> int:
		return 0

var peer = MyPeer.new()

func _ready():
	peer.connect_to_url("ws://localhost:8080")
	get_tree().set_network_peer(peer)

The console pushes this error about every 20ms:

E 0:00:01.320   get_available_packet_count: Please use get_peer(ID).get_available_packet_count to get available packet count from peers when not using the MultiplayerAPI.
  <C++ Error>   Condition "!_is_multiplayer" is true. Returned: 0
  <C++ Source>  modules/websocket/websocket_multiplayer_peer.cpp:101 @ get_available_packet_count()

This means, the overriden method is not called but the hard coded one (edit: this might in fact be caused by this issue). So extending this class is impossible too. This might affect not only these two network classes I tried to extend, but this might be a general problem with all engine-classes exposed to GDScript.

I suppose extending engine classes is something most people expect to be working. If so, we should consider this being a bug to be fixed.

If extending engine classes is not intended to be working, I would appreciate an error message in the editor if the user is trying to do so. Would be still much better than finding out about it later.

Thank you guys for your the clarification and support, I appreciate :)

@mrimvo
Copy link

mrimvo commented Apr 30, 2020

While this ticket is more about extending virtual engine classes, I added another ticket primarily addressing overriding engine classes' functions. It's two separate problems adding up to the fact that extending engine classes is not really working in the moment.

@mrimvo
Copy link

mrimvo commented Apr 30, 2020

@mhilbrunner would you mind to rename this issue to "Make virtual classes extendable from GDScript"? Because this is a general problem with all virtual classes exposed to GDScript.

@Faless
Copy link
Collaborator

Faless commented Aug 7, 2022

This is fixed in 3.x via #63163 and master via #63262 ,

@Faless Faless closed this as completed Aug 7, 2022
@akien-mga akien-mga added this to the 3.5 milestone Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants