Legacy Documentation: Version 5.2
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

NetworkWriter

class in UnityEngine.Networking

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

General purpose serializer for UNET (for serializing data to byte arrays).

Variables

PositionThe current position of the internal buffer.

Constructors

NetworkWriterCreates a new NetworkWriter object.

Public Functions

AsArrayReturns the internal array of bytes the writer is using. This is NOT a copy.
FinishMessageThis fills out the size header of a message begun with StartMessage(), so that it can be send using Send() functions.
SeekZeroSeeks to the start of the internal buffer.
StartMessageThis begins a new message, which should be completed with FinishMessage() once the payload has been written.
ToArrayReturns a copy of internal array of bytes the writer is using, it copies only the bytes used.
WriteThis writes the a reference to a GameObject with a NetworkIdentity component to the stream. The object should have been spawned for clients to know about it.
WriteBytesAndSizeThis writes a 16-bit count and a array of bytes of that length to the stream.
WriteBytesFullThis writes a 16-bit count and an array of bytes of that size to the stream.
WritePackedUInt32This writes the 32-bit value to the stream using variable-length-encoding.
WritePackedUInt64This writes the 64-bit value to the stream using variable-length-encoding.