docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method PtrToNativeArrayWithDefault

    PtrToNativeArrayWithDefault<T>(T, void*, int, int, Allocator)

    Creates a NativeArray from a pointer by first copying length defaultTs into the NativeArray, and then overwriting the data in the array with source, assuming each element in source is sourceElementSize bytes.

    Declaration
    public static NativeArray<T> PtrToNativeArrayWithDefault<T>(T defaultT, void* source, int sourceElementSize, int length, Allocator allocator) where T : struct
    Parameters
    Type Name Description
    T defaultT

    A default version of T, which will be used to first fill the array before copying from source.

    void* source

    A pointer to a contiguous block of data of size sourceElementSize * length.

    int sourceElementSize

    The size of one element in source.

    int length

    The number of elements to copy.

    Allocator allocator

    The allocator to use when creating the NativeArray.

    Returns
    Type Description
    NativeArray<T>

    A new NativeArray populating with defaultT and source. The caller owns the memory.

    Type Parameters
    Name Description
    T

    The type of struct to copy.

    Remarks

    This is useful for native inter-operations with structs that might change over time. This allows new fields to be added to the C# struct without breaking data obtained from data calls.

    In This Article
    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on Friday, September 22, 2023