Skip to content

Commit 7338299

Browse files
committed
Reduced memory allocations in NetworkedTransform
1 parent 2779800 commit 7338299

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

MLAPI/MonoBehaviours/Prototyping/NetworkedTransform.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class NetworkedTransform : NetworkedBehaviour
3131
[Tooltip("If enable proximity is turned on, on clients within this range will be recieving position updates from the server")]
3232
public float ProximityRange = 50;
3333

34+
private static byte[] positionUpdateBuffer = new byte[24];
35+
3436
private void OnValidate()
3537
{
3638
if (!AssumeSyncedSends && InterpolatePosition)
@@ -69,7 +71,7 @@ private void Update()
6971
lastSendTime = Time.time;
7072
lastSentPos = transform.position;
7173
lastSentRot = transform.rotation;
72-
using (MemoryStream writeStream = new MemoryStream(24))
74+
using (MemoryStream writeStream = new MemoryStream(positionUpdateBuffer))
7375
{
7476
using (BinaryWriter writer = new BinaryWriter(writeStream))
7577
{
@@ -151,7 +153,7 @@ private void OnRecieveTransformFromClient(int clientId, byte[] data)
151153
transform.position = new Vector3(xPos, yPos, zPos);
152154
transform.rotation = Quaternion.Euler(new Vector3(xRot, yRot, zRot));
153155
}
154-
using (MemoryStream writeStream = new MemoryStream(24))
156+
using (MemoryStream writeStream = new MemoryStream(positionUpdateBuffer))
155157
{
156158
using(BinaryWriter writer = new BinaryWriter(writeStream))
157159
{

0 commit comments

Comments
 (0)