NetworkIdentity: cache UNetUpdate UpdateVarsMessage

This commit is contained in:
vis2k 2019-02-24 22:27:02 +01:00
parent 7392de2790
commit 5e09d13d6e

View File

@ -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);
}
}