0 votes

I am working on a simple 2D shooter game, using a client/server architecture for networking. I will mostly use TRANSFERMODEUNRELIABLE for game state update messages from server to clients, but I would like to send some important event messages (player joined/left game, chat messages, kill messages...) reliably. Is it okay if I change transfer mode to reliable just before these messages, and change it back to unreliable mode right after? Like this:

#  variable holding NetworkedMultiplayerPeer object
var nmpeer

func _ready():
    #
    #  initialize nmpeer ...
    #

    #  I will mostly use this mode
    nmpeer.set_transfer_mode(TRANSFER_MODE_UNRELIABLE)


func _physics_process(delta):
    #
    #    some code here...
    #    

    #    check if its time to update clients (currently happens every 2nd frame)
    if ( NeedPublish() )
         SendUpdateToClients()

    #  check if some event happened
    if ( SomethingImportantHappened() )
        #  set transfer mode to reliable
        nmpeer.set_transfer_mode(TRANSFER_MODE_RELIABLE)

        SendImportantMessage()

        #  set transfer mode back to unreliable
        nmpeer.set_transfer_mode(TRANSFER_MODE_UNRELIABLE)

Also there are two different methods "rpcid" and "rpcunreliableid", is the first one always reliable? If so can I use them while sending raw packets (via putpacket) without changing transfer mode?

Hope the question was clear and not too long, thank you for reading.

in Engine by (136 points)

1 Answer

0 votes

Just to complete this question, I found out that "send_bytes" function already has a parameter for transfer mode so my question is mostly answered.

Also upon looking source code, it seems "rpc_id" always use reliable channel, although I could not find anything in the documentation that confirms this behavior, however its unreliable counterpart is explicitly mentioned.

by (136 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.