#Multiple Instances Using Same WebRTCMultiplayerPeer instance

19 messages · Page 1 of 1 (latest)

tardy night
#
var rtc_mp: WebRTCMultiplayerPeer
var sealed := false

func _ready():
    rtc_mp = WebRTCMultiplayerPeer.new()
    print("9: created MP: ", rtc_mp)

when I run 4 instances of this they all print the same instance # of WebRTCMultiplayerPeer

gloomy magnet
#

That code itself doesn't do anything to connect the various instances to each other.

You simply create a peer to peer mesh network in the code and then output that into the console, so it seems that the behavior matches the code you posted.

tardy night
#

I already have all the connecting code done, but my whole issue is that all my instances are using the same WebRTCMultiplayerPeer instance

gloomy magnet
#

well with that you create a client and a server, that then connect to each other. when you create these instance classes locally why would they be different?

when you say you have all the connecting code done, does thst mean everything works?

#

once they connect to your host or the host sets up the game they all have unqieu id's assigned

#

host 1, other okays a combination of numbers

#

based on your snippet alone you would see the same result since you're just outputting an new rtc_mp class.

tardy night
# gloomy magnet well with that you create a client and a server, that then connect to each other...

@gloomy magnet here's my connection code:

func _connected(id, data, use_mesh):
    print("56: Connected %s, mesh: %s, data: %d" % [id, use_mesh, data])
    if use_mesh:
        rtc_mp.create_mesh(data)
    elif data == "1":
        rtc_mp.create_server()
    else:
        rtc_mp.create_client(data.to_int())

    multiplayer.multiplayer_peer = rtc_mp
    print("66: MULTIPLAYER: ", multiplayer)
    print("67: MULTIPLAYER::PEER: ", multiplayer.multiplayer_peer)

I noticed after some debugging that rtc_mp.create_server nor rtc_mp.create_client is ever hit this is because use_mesh is always true in my case. I'm I miss understanding this demo ?

GitHub

Demonstration and Template Projects. Contribute to godotengine/godot-demo-projects development by creating an account on GitHub.

tardy night
gloomy magnet
#

https://www.youtube.com/watch?v=n8D3vEx7NAE I followed this tutorial which was highly instructive. The demo project looks quite complicated to parse if you just started with multiplayer stuff

How to make a simple online multiplayer FPS game in Godot 4 and play with friends over the internet. Big thank you to @ditzyninja for his Godot 4 networking content!
Git Repo: https://github.com/devloglogan/MultiplayerFPSTutorial

0:00 Intro

=== Blender Modeling ===
0:34 Environment Model
3:48 Pistol Model

=== Godot 4 Project Setup ===
6:56 Im...

▶ Play video
#

I would start completely fresh and set up your own project with all the networking code written yourself, following this or other tutorials

#

Trying to use the Demo project and changing up some code will likely just frustrate you

#

I noticed after some debugging that rtc_mp.create_server nor rtc_mp.create_client is ever hit this is because use_mesh is always true <- You are connecting to a signal on ws_webrtc_client.gd, because thats what the client script extends from, so you'll have to adjust signal connected(id, use_mesh) accordingly if you want to get other information from it

#

On a side node, please ask the person before PMing them out of the blue 🙂

tardy night
#

In case anyone comes across this I had a missing piece in my signaling server where on PEER_CONNECT I was sending PEER_CONNECT to existing peers, but not sending the new peer the PEER_CONNECT of existing peers. I also did some script restructering in fear of my WebRTCMultiplayerPeer being a singleton.