Version: 5.4
public bool OnSerialize (Networking.NetworkWriter writer, bool initialState);

Parámetros

writer Writer usado para escribir hacia el stream.
initialState Indica si está siendo llamado al estado inicial de envío.

Valor de retorno

bool Devuelve true si los datos fueron escritos.

Descripción

Función virtual para sobreescribir el envío personalizado de datos serializados.

The initialState flag is useful to differentiate between the first time an object is serialized and when incremental updates can be sent. The first time an object is sent to a client, it must include a full state snapshot, but subsequent updates can save on bandwidth by including only incremental changes. Note that SyncVar hook functions are not called when initialState is true, only for incremental updates.

If a class has SyncVars, then an implementation of this function and OnDeserialize() are added automatically to the class. So a class that has SyncVars cannot also have custom serialization functions.

La función OnSerialize debería devolver true para indicar que una actualización debería ser enviada. Si devuelve true, entonces los dirty bits (bits sucios) para ese script son configurados a cero, si devuelve false entonces los dirty bits no cambian. Esto permite a que multiplos cambios a un script sean acumulados en el tiempo y enviados cuando el sistema está listo, en vez de cada frame.