mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkIdentity: cache UNetUpdate UpdateVarsMessage
This commit is contained in:
parent
7392de2790
commit
5e09d13d6e
@ -909,6 +909,11 @@ internal void Reset()
|
||||
clientAuthorityOwner = null;
|
||||
}
|
||||
|
||||
|
||||
// UNetUpdate is in hot path. caching the vars msg is really worth it to
|
||||
// avoid large amounts of allocations.
|
||||
static UpdateVarsMessage varsMessage = new UpdateVarsMessage();
|
||||
|
||||
// invoked by unity runtime immediately after the regular "Update()" function.
|
||||
internal void UNetUpdate()
|
||||
{
|
||||
@ -921,14 +926,10 @@ internal void UNetUpdate()
|
||||
byte[] payload = OnSerializeAllSafely(false);
|
||||
if (payload != null)
|
||||
{
|
||||
// construct message and send
|
||||
UpdateVarsMessage message = new UpdateVarsMessage
|
||||
{
|
||||
netId = netId,
|
||||
payload = payload
|
||||
};
|
||||
|
||||
NetworkServer.SendToReady(this, (short)MsgType.UpdateVars, message);
|
||||
// populate cached UpdateVarsMessage and send
|
||||
varsMessage.netId = netId;
|
||||
varsMessage.payload = payload;
|
||||
NetworkServer.SendToReady(this, (short)MsgType.UpdateVars, varsMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user