Skip to content

Commit dc2094d

Browse files
fix: remove optimization that breaks Unity Transport Adapter (#1205)
* This code breaks the Unity Transport Adapter and assumes specific behavior that wasn't present before, in UTA we assume that these kind of checks are not happening in the SDK. This is because its very possible that you're clientID on the server (which is synchronized via OwnerClientId) and your ServerId could indeed be the same and it shouldn't really matter if they are as one side should not impact the other side. So for this reason we have removed this check.
1 parent 92fc3e6 commit dc2094d

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,19 @@ internal void __sendServerRpc(ref FastBufferWriter writer, uint rpcMethodId, Ser
6868
},
6969
RpcData = writer
7070
};
71+
72+
// If we are a server/host then we just no op and send to ourself
73+
if (IsHost || IsServer)
74+
{
75+
var tempBuffer = new FastBufferReader(ref writer, Allocator.Temp);
76+
message.Handle(ref tempBuffer, NetworkManager, NetworkBehaviourId);
77+
tempBuffer.Dispose();
78+
79+
return;
80+
}
81+
7182
var rpcMessageSize = NetworkManager.SendMessage(message, networkDelivery, NetworkManager.ServerClientId, true);
83+
7284
#if DEVELOPMENT_BUILD || UNITY_EDITOR
7385
if (NetworkManager.__rpc_name_table.TryGetValue(rpcMethodId, out var rpcMethodName))
7486
{

com.unity.netcode.gameobjects/Runtime/Messaging/MessagingSystem.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -420,23 +420,6 @@ internal unsafe int SendMessage<TMessageType, TClientIdListType>(in TMessageType
420420
MessageType = m_MessageTypes[typeof(TMessageType)],
421421
};
422422

423-
424-
if (clientId == m_LocalClientId)
425-
{
426-
m_IncomingMessageQueue.Add(new ReceiveQueueItem
427-
{
428-
Header = header,
429-
Reader = new FastBufferReader(ref tmpSerializer, Allocator.TempJob),
430-
SenderId = clientId,
431-
Timestamp = Time.realtimeSinceStartup
432-
});
433-
for (var hookIdx = 0; hookIdx < m_Hooks.Count; ++hookIdx)
434-
{
435-
m_Hooks[hookIdx].OnAfterSendMessage(clientId, typeof(TMessageType), delivery, tmpSerializer.Length + sizeof(MessageHeader));
436-
}
437-
continue;
438-
}
439-
440423
writeQueueItem.Writer.WriteValue(header);
441424
writeQueueItem.Writer.WriteBytes(tmpSerializer.GetUnsafePtr(), tmpSerializer.Length);
442425
writeQueueItem.BatchHeader.BatchSize++;

0 commit comments

Comments
 (0)