docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method TryBeginWriteValue

    TryBeginWriteValue<T>(in T)

    Allows faster serialization by batching bounds checking. When you know you will be writing multiple fields back-to-back and you know the total size, you can call TryBeginWrite() once on the total size, and then follow it with calls to WriteValue() instead of WriteValueSafe() for faster serialization.

    Unsafe write operations will throw OverflowException in editor and development builds if you go past the point you've marked using TryBeginWrite(). In release builds, OverflowException will not be thrown for performance reasons, since the point of using TryBeginWrite is to avoid bounds checking in the following operations in release builds. Instead, attempting to write past the marked position in release builds will write to random memory and cause undefined behavior, likely including instability and crashes.

    Declaration
    public bool TryBeginWriteValue<T>(in T value) where T : unmanaged
    Parameters
    Type Name Description
    T value

    The value of the type T you want to write

    Returns
    Type Description
    bool

    True if the write is allowed, false otherwise

    Type Parameters
    Name Description
    T

    The value type to write

    Exceptions
    Type Condition
    InvalidOperationException

    If called while in a bitwise context

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)