Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Add

Adds a new item. If the item is already present in the collection, this method should throw, but currently does not! Instead, it returns false without replacing said item.
Read time 1 minuteLast updated 12 days ago

Definition

  • Type: Method
  • Namespace: Unity.Collections
  • Assembly: UnityEngine.ManagedKernelModule

Add(T)

Adds a new item. If the item is already present in the collection, this method should throw, but currently does not! Instead, it returns false without replacing said item.
public bool Add(T item)

Parameters

item

T
The value to add.

Returns

Type

Description

boolTrue if the value is not already present.

Remarks

Prefer NativeParallelHashSet<T>.ParallelWriter.TryAdd if your intent is to allow graceful failure, as this API will eventually become more strict (and begin to throw).

Add(T, int)

Adds a new item. If the item is already present in the collection, this method should throw, but currently does not! Instead, it returns false without replacing said item.
public bool Add(T item, int threadIndexOverride)

Parameters

item

T
The value to add.

threadIndexOverride

The thread index which must be set by a field from a job struct with the NativeSetThreadIndexAttribute attribute.

Returns

Type

Description

boolTrue if the value is not already present.

Remarks

Prefer NativeParallelHashSet<T>.ParallelWriter.TryAdd if your intent is to allow graceful failure, as this API will eventually become more strict (and begin to throw).