Movement delays chat messages - is Network Channels a solution ?

Hi Everyone !

I made a multiplayer game. In my game you can move objects around with the mouse. All these moveable objects are networked so that their position is synced over all clients. My game also has a chat function function, but unfortunately all the chat messages are delayed after dragging an object. I believe all the network messages are pilling up (when dragging an object) and are arriving later on the clients (then when not draging objects).

Besides making the networking code of the drageable objects more efficient, can this problem be solved by other means? Can i have two networking queue’s ? one for objects, one for the chat? Or is this not what channels are for?

here is the game => www.suchhacks.com <= :slight_smile:

Any help much appreciated !
Thnx

-J

Try using different channels and see if that solves it.

@LukeDawn1 I added a custom channel for the chatmessages, and used the following code for communication but without results :cry:

NetworkServer.SendByChannelToAll (CHAT_MSG, strMsg, chatChannel);
client.SendByChannel (CHAT_MSG, strMsg, chatChannel);

That is sad. I hoped that the different channels would have different queues internally. I’m pretty certain that one of the devs mentioned that there will be more queues in the next patch of uNet.

Are you sending your chat as reliable, and the stream of movement updates as unreliable?

But do multiple channels automatically run in (pseudo) parallel? or is it just some ways of defining and distinguishing the QOS type of the messages? That’s the question.

Another question: i’m setting the position of the networked objects when dragging in the client using the following code. It works but it is lagging a lot. Is the correct way to do it? Or do i have to explicitely use syncvars on the server, then let the dragable objects update to those syncvars on their own scripts / Update() method?

Thank you!

…

if (isLocalPlayer)
{
if (isDraggingObject)
{
//move the position on the server
Cmd_moveObjectToPosion(go, newposition);
//move the position locally (so we don’t have a delay)
go.transform.position = newposition;
}
}

[Command]
void Cmd_moveObjectToPosition(GameObject obj, Vector3 pos)
{
NetworkIdentity objId = obj.GetComponent();

objId.AssignClientAuthority(connectionToClient);

Rpc_moveObjectToPosition(pos)

objId.RemoveClientAuthority(connectionToClient);
}

[ClientRpc]
void Rpc_moveObjectToPosition(GameObject obj,Vector3 pos)
{
//if not moved by local player update the position coming from the server
if(!obj.GetComponent().hasAuthority)
{
obj.transform.position = pos;
}
}

How often are you sending the new position? If you try to do it every frame, that will lag. Try it with 10 or 20 updates per second max, and use interpolation/prediction if needed.

@LukeDawn1 , I’m sending it every Update lol, silly me. That will be the cause of all these problems! How would you propose to do this? Can i overwrite the networkSendInterval of the objects?

public override float GetNetworkSendInterval ()
{
return 0.3f;
}

Or do i need some kind of if statement with an incrementing time offset in my update method?

Quite new to this :slight_smile:
Thnx !

EDIT: i will try to do it with a coroutine with a waitForSeconds(.2f) and start and stop it when start/finish dragging :slight_smile: keep you posted

Use FixedUpdate() - I have mine set to 20 times a second, and use a divider to ensure I’m sending only 10 times a second. It’s one of those things most people say you shouldn’t use much, but I’ve found it perfect for movement.

The Network Send Interval just packages everything up and sends these larger packages at the given interval. So if it’s movement alone, most of those messages are going to be old. You only want to send what’s current.

I don’t know much about using NetworkTransforms (nothing in fact), I have my own system using NetworkWriter and NetworkReader classes.

I used a coroutine while dragging… and it works great. Otherwise the object will send data every fixed update even when it is standing still right?

I have another question: I want my dragable objects to be intitialized (position-wise) on the client when it connects to the server. This doesn’t work, it only updates the position of the objects when a player is dragging an object. In other words, all objects are initialized with their positions of the client-scene. I want all objects to be initialized on the client with their respective position on the server. Somehow i want to trigger a syncvar update. I don’t know how to accomplish this. :frowning:

I can’t help on that one, as I don’t use syncvars. I would keep a list of all objects so that when a player connects the server can supply it with a list of all the objects and positions.

Ok i fixed it, I wasn’t correctly spawning the objects on the server :slight_smile:
Thank you so much for all your help!

and give www.suchhacks.com another visit :wink:

1 Like